[Gdal-dev] convert a group of points (lat, lon) to a shape file

Xiaodong Zhang zhang at aero.und.edu
Thu Jun 23 12:04:06 EDT 2005


Hi Frank,

Thanks for the help. I'm almost there, but still have one problem. I can create
a shapefile for points but get an error for polygon.

[run:]$ ogr2ogr -f "ESRI Shapefile" test merja.vrt

ERROR 1: Attempt to write non-polygon (POINT) geometry to  type shapefile.
ERROR 1: Terminating translation prematurely after failed
translation of layer MyAOI

[run:]$ cat merja.vrt
<OGRVRTDataSource>

    <OGRVRTLayer name="MyAOI">
        <SrcDataSource relativeToVRT="1">AOIs</SrcDataSource>
 	<SrcLayer>aoi1</SrcLayer>
	<GeometryType>wkbPolygon</GeometryType>
        <LayerSRS>WGS84</LayerSRS>
	<GeometryField encoding="PointFromColumns" x="x" y="y"/>
    </OGRVRTLayer>

</OGRVRTDataSource>

[run:]$ cat AOIs/aoi1.csv
id, x, y
1, -100, 40
2, -90, 40
3, -90, 39
4, -100, 39
5, -100, 40

Thanks
Xiaodong


Quoting Frank Warmerdam <fwarmerdam at gmail.com>:

> On 6/22/05, Xiaodong Zhang <zhang at aero.und.edu> wrote:
> > Hi,
> > 
> > I have a humble question which may have been answered before, but could
> > anybody please kindly help out. The question is:
> > 
> > If I have a series of points, say in a text file, like
> > lat1, lon1
> > lat2, lon2
> > lat3, lon3
> > lat4, lon4
> > 
> > How should I format the text file such that an ogr utility (e.g.,
> > ogr2ogr) can convert it into a shapefile as a polygon.
> 
> Xiaodong,
> 
> Perry's suggestion should work well.  Another alternative
> is to treat your file as a .csv file, and then write a small VRT
> file to show OGR how to treat the columns as x/y values of a point.
> Then use ogr2ogr to convert it to a shapefile. 
> 
> See:
> 
>   http://www.gdal.org/ogr/drv_csv.html
>   http://www.gdal.org/ogr/drv_vrt.html
> 
> 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
> and watch the world go round - Rush    | Geospatial Programmer for Rent
> 





More information about the Gdal-dev mailing list