[gdal-dev] GML to Shapefile

Frank Warmerdam warmerdam at pobox.com
Wed Jul 2 06:29:25 EDT 2008


Stefan,

Unfortunately you have not provided enough of your GML file to
tell what is going on.  It appears that the features with the line
and polygon geometries are of the same feature class (that is will
appear as one layer in OGR).  If this is the case, then only one
shapefile will be created and it will be assigned a geometry type
based on the first feature geometry encountered during the transfer.

Assuming it does not make sense to restructure the GML file, I
would suggest you do something like:

ogr2ogr -skipfailures -f "ESRI Shapefile"
     out_line.shp mydata.gml mydata_layer -nlt LINESTRING

ogr2ogr -skipfailures -f "ESRI Shapefile"
     out_poly.shp mydata.gml mydata_layer -nlt POLYGON

Please replace "mydata_layer" with the name of the layer (feature
class) holding the line/polygon geometries.  These commands are
essentially attempting to translate the layer twice, onces as lines
and once as polygons.

Best regards,

Stefan Keller wrote:
> Hi,
>  
> I tried to convert a GML file to Shapefile whereas the GML contains 
> points, linestrings and polygons (see GML snippet below).
>  
> The command goes something like this: % ogr2ogr -f "ESRI Shapefile" 
> outdir mydata.gml
>  
> Now, what I'm getting out is mydata.shp (+.dbf/shx) and alayer.shp 
> (+.dbf/shx), where mydata contains point type and alayer contains 
> linestring type.  => Why is there an additional linestring shapefile but 
> no polygon shapefile?
>  
> -- Stefan
>  
> GML snippet of mydata.gml:
> ...
> <gml:featureMember>
> <osm:way fid="4304746">
> <osm:id>4304746</osm:id>
> <osm:timestamp>2008-03-25T21:31:01+00:00</osm:timestamp>
> <osm:user>Schäuble Michele</osm:user>
> <osm:geometryProperty>
> <gml:polygonMember>
> <gml:Polygon>
> <gml:outerBoundaryIs>
> <gml:LinearRing>
> <gml:coordinates>8.8971245,47.2066117 8.8958854,47.2065926 
> 8.8951875,47.2061166 8.893922,47.2073953 8.8921772,47.2079074  ...  
> 8.8971383,47.2051962 8.8962002,47.2044168 8.8955145,47.2051218 
> 8.8966504,47.2060895 8.8971132,47.2060825 8.8971245,47.2066117 
> </gml:coordinates>
> </gml:LinearRing>
> </gml:outerBoundaryIs>
> </gml:Polygon>
> </gml:polygonMember>
> </osm:geometryProperty>
> <osm:natural>water</osm:natural>
> </osm:way>
> </gml:featureMember>
> <gml:featureMember>
> <osm:way fid="4684550">
> <osm:id>4684550</osm:id>
> <osm:timestamp>2008-04-28T16:55:00+01:00</osm:timestamp>
> <osm:user>Schäuble Michele</osm:user>
> <osm:geometryProperty>
> <gml:LineString>
> <gml:coordinates>8.8370022,47.2301952 8.8368472,47.2301807 
> 8.8355139,47.2296331 8.832977,47.2291911 8.8297158,47.2285296 
> 8.8256068,47.2278459 8.8223489,47.2273065 8.8188251,47.2267218 
> 8.8183819,47.2267204 </gml:coordinates>
> </gml:LineString>
> </osm:geometryProperty>
> <osm:highway>primary</osm:highway>
> </osm:way>
> </gml:featureMember>
> ....
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the gdal-dev mailing list