Changes between Version 26 and Version 27 of BluePrint/GIS/ShapefileLayers
- Timestamp:
- 05/17/13 13:36:49 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
BluePrint/GIS/ShapefileLayers
v26 v27 38 38 39 39 === Import into native Tables === 40 41 See below for code to convert SHP to an lxml.etree for import using XSLT 42 40 43 Paul Porthouse [2013-04-27 at the [http://mapaction.org MapAction] Hackathon]: 41 44 42 Our idea is to use a basic web form with a file upload (similar to the Import from OpenStreetMap) where you can select which ShapeFile to use. You should also be able to set basic information including database connection details. This will then upload the shape and use OGR2OGR to convert the ShapeFile to geometry and import it into the specified database.45 Our idea is to use a basic web form with a file upload (similar to the Import from !OpenStreetMap) where you can select which Shapefile to use. You should also be able to set basic information including database connection details. This will then upload the shape and use OGR2OGR to convert the Shapefile to geometry and import it into the specified database. 43 46 44 47 A basic OGR2OGR which should accomplish the import is: … … 52 55 {{{ 53 56 ''' 54 Dump the contents of a shapefile to an lxml etree object55 Assumes the shapefile is encoded in UTF-8 format56 Tested with TM_WORLD_BORDERS-0.3.shp57 Dump the contents of a shapefile to an lxml etree object 58 Assumes the shapefile is encoded in UTF-8 format 59 Tested with TM_WORLD_BORDERS-0.3.shp 57 60 ''' 61 58 62 import sys 59 63 import ogr … … 70 74 layername = os.path.splitext(os.path.basename(shapefilename))[0] 71 75 72 # Create the datasource76 # Create the datasource 73 77 ds = ogr.Open( shapefilename ) 74 78 75 # Open the shapefile79 # Open the shapefile 76 80 if ds is None: 77 81 print "Open failed.\n" 78 82 sys.exit(0) 79 83 80 # Get the layer and iterate through the features84 # Get the layer and iterate through the features 81 85 lyr = ds.GetLayer(0) 82 86 … … 111 115 112 116 113 # Test the etree object117 # Test the etree object 114 118 xmlString = etree.tostring(root, pretty_print=True) 115 119 f = open("test.xml","w") … … 117 121 }}} 118 122 119 120 123 ---- 121 124 [wiki:BluePrint/GIS GIS BluePrints]