[gdal-dev] How to convert line string to point or polygon to line
string (e.g. shapefile to gpx conversion)
Even Rouault
even.rouault at mines-paris.org
Thu Sep 10 15:22:50 EDT 2009
Selon Stefan Keller <sfkeller at gmail.com>:
Hi Stefan,
> Dear all,
>
> Given for example a shapefile containing polygons (or polylines, even
> multiple...) and GPX as the target format: How can one convert this to
> line strings (or points)?
There's no direct way of doing this.
>
> Discussion: I understand that there are two possibilities, either the
> input reader is instructed (and capable) to convert polygons (or
> polylines) to OGR type wkbLineString
Right
or the output converter takes OGR
> type wkbPolygon and is instructed (and capable) to write line strings
> (holds correspondingly to converting polyline to points).
Right
>
> Any solutions?
One issue I see is that : does it make sense to write a polygon into a GPX file
that he's not a generic purpose vector format.
The GPX driver doc says :
"Supported geometries :
* Features of type wkbPoint/wkbPoint25D are written in the wpt element.
* Features of type wkbLineString/wkbLineString25D are written in the rte
element.
* Features of type wkbMultiLineString/wkbMultiLineString25D are written in
the trk element.
* Other type of geometries are not supported."
The issue I see is : how do you convert a polygon into a linestring. Do you only
take the external ring of the polygon, or do you create as many geometries as
external and internal rings ?
Anyway, using the OGR API, you can certainly read the source feature and
geometries and transform them in an appropriate way for the destination driver.
You could extend the OGRGeometryFactory class that has a few forceXXX() methods
to transform from a geometry type to another one. They are for example used by
ogr2ogr.cpp.
Best regards,
Even
>
> -S.
>
> P.S. Background: I'm running an online converter (geoconverter.hsr.ch)
> which simply uses OGR and I often get service requests like this from
> OGR freshmans.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
More information about the gdal-dev
mailing list