GMLAS link: http://www.gdal.org/drv_gmlas.html

I want to convert my gml file to shapefiles. But our gml files was created by custom gml schema. We have their application schema, xsd. But i don't know how to put this schema path on command prompt or python ide. I downloaded fwtools, ogr2ogr main python code but i don't know to use. Do you know how?

  • Don't use FWTools, it is out of date (with an ancient GDAL 1.6 or 1.7) and no longer supported. Use OSGeo4W. The GMLAS driver is only available in GDAL >= 2.2 – user2856 Apr 24 '18 at 7:33
  • Okay. so as i know osgeo4w can be downloaded and is used to install gdal ogr libraries. But it's relevant because i used ogr2ogr.py main file and couldn't success and i still don't know what is this syntax and where do i have to put .xsd schema path to convert gml to shp. Thanks again. – Umut Üçok Apr 24 '18 at 7:41

I've never used GMLAS, but the documentation shows you would use something like:

ogr2ogr -f "ESRI Shapefile" -oo XSD=input.xsd output.shp input.gml

The ogr2ogr doc shows that -oo can be used to specify format specific open options. The GMLAS driver page you link to shows the available open options for the GMLAS format.

You can do this in python using the GDAL python API with:

in_ds = gdal.OpenEx('input.gml', open_options=['XSD=input.xsd' ])
out_ds = gdal.VectorTranslate('output.shp', in_ds, format = 'ESRI Shapefile')

But you could also just use

subprocess.check_output(['ogr2ogr', '-f', "ESRI Shapefile", '-oo', 'XSD=input.xsd', 'output.shp', 'input.gml']) 
  • Thank you so much. I tried GDAL python api, appears epsg code error but it is not important because osgeo shows same error too. however, end of the traceback, it shows : "ERROR 1: hSrcDS == NULL" . I couldn't find out how to resolve. Additionally i tried to run as using subprocess: i assigned osgeo.bat path, .xsd file and gml files but it is not successful again : 'subprocess.check_output(osgeoshell, ['-f', "ESRI Shapefile" '-oo', 'XSD=%s' % muipxsd, shpoutputs, muipgml]) ' – Umut Üçok Apr 25 '18 at 9:32

@user2865 Thanks

For me it works to transform cityGml to shapefiles

xsd = "XSD=http://schemas.opengis.net/citygml/landuse/1.0/landUse.xsd,http://schemas.opengis.net/citygml/cityfurniture/1.0/cityFurniture.xsd,http://schemas.opengis.net/citygml/texturedsurface/1.0/texturedSurface.xsd,http://schemas.opengis.net/citygml/transportation/1.0/transportation.xsd,http://schemas.opengis.net/citygml/building/1.0/building.xsd,http://schemas.opengis.net/citygml/waterbody/1.0/waterBody.xsd,http://schemas.opengis.net/citygml/relief/1.0/relief.xsd,http://schemas.opengis.net/citygml/vegetation/1.0/vegetation.xsd,http://schemas.opengis.net/citygml/cityobjectgroup/1.0/cityObjectGroup.xsd,http://schemas.opengis.net/citygml/generics/1.0/generics.xsd"
in_ds = gdal.OpenEx("GMLAS:" + inputFile, open_options=[xsd, "REMOVE_UNUSED_LAYERS=YES"])
out_ds = gdal.VectorTranslate(outputFolder, in_ds, format = 'ESRI Shapefile', layerCreationOptions = ["SCHEMA=citymodel"])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.