[gdal-dev] help! convert GML to Shp by using python

Xiaoyu Guan guanxiaoyu at gmail.com
Thu Dec 18 03:30:34 EST 2008

Hi Frank:
Thanks very much for your reply.
About GML files, actually, I grab The GML files from OpenLayers.org.
as you know OpenLayers can read GML files directly.
The GML which i used is located at
You have to change xml to gml by yourself.
The commend which I used for converting is that
> ogr2ogr -f "ESRI Shapefile" polygon.shp multipolygon.gml
the above commend will create few shp files, so I have also tried another
> ogr2ogr -f "ESRI Shapefile" polygon.shp multipolygon.gml multipolygon
this one will create one shapefile.
but the polygon.shp file does not contain the first feature's and the third
feature's attribute

I think the vec_tr.py is very helpful to me, espeically, WalkandTransform
I would contact you when I have some results.

All the best


On Wed, Dec 17, 2008 at 6:38 PM, Frank Warmerdam <warmerdam at pobox.com>wrote:

> Xiaoyu Guan wrote:
>> Dear All:
>> I would like to use GDAL/OGR library for converting GML files to Shp
>> files. I have look around on internet. there are a lot of people use OGR2OGR
>> convert them. I have already try use ogr2ogr , convert gml to shp.
>> unfornately, the result is not what I expected. for example. I convert one
>> ploygon file, there are few attributes lost. So I would like to know how to
>> write a python script to done the job.
>> Is possbile that somebody give me some hints? for example how many steps
>> to slove the problems? what is the data flow?
> Xiaoyu,
> It might be helpful if you provided a sample GML file you would like to
> translate and explained the problem you encountered using ogr2ogr.
> If you use the Python bindings for OGR to read the GML file it is
> possible you will see similar problems to ogr2ogr since the data
> access mechanism is the same.  The OGR GML driver certainly has many
> problems with sophisticated GML.
> I think the following script should give an idea how to read data
> from one OGR datasource, and write it to another.  The script is
> also intended to provide a hook function to apply transformations to
> the coordinates though I don't think you will need this aspect.
>  http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/vec_tr.py
> Best regards,
> --
> ---------------------------------------+--------------------------------------
> I set the clouds in motion - turn up   | Frank Warmerdam,
> warmerdam at pobox.com
> light and sound - activate the windows | http://pobox.com/~warmerdam<http://pobox.com/%7Ewarmerdam>
> and watch the world go round - Rush    | Geospatial Programmer for Rent

Xiaoyu Guan (Sam)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20081218/95c891a2/attachment-0001.html

More information about the gdal-dev mailing list