INSERT INTO lulc_world_para 
 SELECT osm_id, 
 		"type",
		"name",
		(CASE				
			WHEN type ='residential' OR type='garages' THEN 11
			WHEN type = 'railway' OR type = 'port' OR type = 'harbour' OR type = 'industrial' OR type = 'commercial' OR type = 'retail' OR type = 'lock' OR type = 'marina' OR type = 'aerodrome' THEN 12
			WHEN type = 'quarry' OR type = 'landfill' OR type = 'brownfield' OR type = 'construction' THEN 13
			WHEN type = 'allotments' OR type = 'cemetery' OR type = 'garden' OR type = 'raceway' OR type = 'golf_course' OR type = 'park' OR type = 'common' OR type = 'pitch' OR type = 'playground' OR type = 'recreation_ground' OR type = 'sports_centre' OR type = 'stadium' OR type = 'village_green' OR type = 'zoo' OR type = 'track' THEN 14
			WHEN type = 'farm' OR type = 'farmland' OR type = 'farmyard' OR type = 'greenhouse' OR type = 'greenhouse_horticulture' THEN 21
			WHEN type = 'vineyard' OR type = 'orchard' THEN 22
			WHEN type = 'meadow' THEN 23
			WHEN type = 'forest' OR type = 'wood' THEN 31
			WHEN type = 'grass' OR type = 'greenfield' OR type = 'scrub' OR type = 'heath' OR type = 'grassland' THEN 32
			WHEN type = 'cliff' OR type = 'sand' OR type = 'scree' OR type = 'beach' OR type = 'mud' OR type = 'glacier' OR type = 'fell' OR type = 'rock' THEN 33
			WHEN type = 'wetland' OR type = 'march' THEN 41
			WHEN type = 'salt_pond' OR type = 'tidal' THEN 42
			WHEN type = 'water' OR type = 'riverbank' OR type = 'reservoir' OR type = 'basin' OR type = 'dock' OR type = 'canal' OR type = 'pond' THEN 5
		END)::smallint as class_code,
-- ST_astext(
--ST_Multi(ST_Union(
( "_a_remove_overlaps"(osm_id, the_geom) )::geometry(MULTIPOLYGON,3857)
 --)
 as the_geom 
 ,

 CASE
			WHEN naturals.osm_id > 0 THEN (SELECT ways.tstamp FROM ways WHERE ways.id = naturals.osm_id)
			ELSE (SELECT relations.tstamp FROM relations WHERE relations.id = - naturals.osm_id)
		END AS "timestamp"	
 FROM naturals
 WHERE 
 --http://overpass-api.de/api/map?bbox=-81.42855,30.30244,-81.42605,30.30362
 -- RLP 8.6,48.9,6.5,51.0
--ST_Intersects(naturals.the_geom, ST_MakeEnvelope(8.6,48.9,6.5,51.0, 4326))
--    ST_ContainsProperly(ST_MakeEnvelope($bbox_part, 4326),naturals.the_geom)
${spatialfilter}
    --AND st_isvalid(the_geom)
    --AND st_issimple(the_geom)
	AND (
 type = 'residential' OR type = 'garages' OR type = 'railway' OR type = 'port' OR type = 'harbour' OR type = 'industrial' OR type = 'commercial' OR type = 'retail' OR type = 'lock' OR type = 'marina' OR type = 'aerodrome' 
	OR type = 'quarry' OR type = 'landfill' OR type = 'brownfield' OR type = 'construction' OR type = 'allotments' OR type = 'cemetery' OR type = 'garden' OR type = 'raceway' OR type = 'golf_course' OR type = 'park' 
	OR type = 'common' OR type = 'pitch' OR type = 'playground' OR type = 'recreation_ground' OR type = 'sports_centre' OR type = 'stadium' OR type = 'village_green' OR type = 'zoo' OR type = 'track'
	OR type = 'farm' OR type = 'farmland' OR type = 'farmyard' OR type = 'greenhouse' OR type = 'greenhouse_horticulture' OR type = 'vineyard' OR type = 'orchard' OR type = 'meadow' OR type = 'forest' 
	OR type = 'wood' OR type = 'grass' OR type = 'greenfield' OR type = 'scrub' OR type = 'heath' OR type = 'grassland' OR type = 'cliff' OR type = 'sand' OR type = 'scree' 
	OR type = 'beach' OR type = 'mud' OR type = 'glacier' OR type = 'fell' OR type = 'rock' OR type = 'wetland' OR type = 'march' OR type = 'salt_pond' OR type = 'tidal' OR type = 'water' OR type = 'riverbank' 
	OR type = 'reservoir' OR type = 'basin' OR type = 'dock' OR type = 'canal' OR type = 'pond'
	)
--WHERE ST_IsEmpty(dirty.the_geom) = false
--GROUP BY osm_id,"name",type, class_code, "timestamp"
--HAVING ST_IsEmpty(the_geom) = false
;
