Advertisement
Guest User

Untitled

a guest
Apr 14th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. ogr2ogr -f "PostgreSQL" PG:"host=* port=* dbname=* user=* password=*" RoFRS_v201701.gml -overwrite -progress --config PG_USE_COPY YES
  2.  
  3. Geometry: Polygon
  4. Feature Count: 2130752
  5. Extent: (134111.801000, 11510.471300) - (655988.124900, 657600.687500)
  6. Layer SRS WKT:
  7. (unknown)
  8. OBJECTID: Integer (0.0)
  9. PROB_4BAND: String (8.0)
  10. SUITABILITY: String (25.0)
  11. PUB_DATE: Integer (0.0)
  12. RISK_FOR_INSURANCE_SOP: String (3.0)
  13. SHAPE_Length: Real (0.0)
  14. SHAPE_Area: Real (0.0)
  15.  
  16. ogrinfo PG:"host=* port=* dbname=* user=* password=*" -sql "CREATE EXTENSION postgis;"
  17.  
  18. ogr2ogr -f "PostgreSQL" PG:"host=* port=* dbname=* user=* password=*" RoFRS_v201701.gml -overwrite -progress -oo GML_ATTRIBUTES_TO_OGR_FIELDS=YES
  19.  
  20. - Ensures the geom column contains geometry of plain,
  21. ST_MultiPolygon and not the variant with additional dimensions
  22.  
  23. -- Run the queries below to check the type of geometry currently stored
  24. -- in the geom column
  25. -- SELECT DISTINCT ST_GeometryType(geom) FROM schema.table; -- We want ST_MultiPolygon
  26. -- SELECT DISTINCT ST_NDims(geom) FROM schema.table; -- We want 2
  27.  
  28. -- If the above reports > 2 dimensions, you can force it to 2d by:
  29. -- Adding an additional column called geom_2d of the correct type and projection
  30. ALTER TABLE schema.table
  31. ADD COLUMN geom_2d geometry(MultiPolygon,27700);
  32. -- UPDATing that new column by passing the original geometry through the ST_Force2D
  33. -- PostGIS function
  34. UPDATE schema.table SET geom_2d = ST_Force2D(geom);
  35. -- Dropping the original geometry
  36. ALTER TABLE schema.table DROP COLUMN geom;
  37. -- Renaming the new column to geom
  38. ALTER TABLE schema.table RENAME COLUMN geom_2d TO geom;
  39. -- Clean up any duplicate vertices and other geometry problems
  40. DELETE FROM schema.table WHERE ST_Area(geom) = 0.0;
  41. UPDATE schema.table
  42. SET geom = ST_Multi(ST_Buffer(geom, 0.0))
  43. WHERE NOT ST_IsValid(geom);
  44.  
  45. -- And adding a spatial index to the new column
  46. CREATE INDEX sidx_table_geom
  47. ON schema.table
  48. USING gist
  49. (geom);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement