using ogr2ogr to create pt shp file from dbf w/ lat-lon fields

Emilio Mayorga emiliomayorga at GMAIL.COM
Wed Mar 22 21:05:20 PST 2006


On 3/22/06, Frank Warmerdam <warmerdam at pobox.com> wrote:
> Emilio Mayorga wrote:
> > I have a polygon shape file that has lat & lon fields for the centroid
> > (the polygons are simple rectangles). I'd like to write a simple batch
> > process to read those lat-lon fields and create a point shape file
> > that also includes all the other attributes. I'd like to keep this as
> > simple as possible, so I figured I could use ogr2ogr.
> >
> > It sounds like I need to set up a Virtual Spatial Data file. The
> > "Virtual Spatial Data (ODBC/OVF)" MapServer document says that I could
> > use an ODBC connection after setting up a DSN. I have unixODBC
> > installed on a RedHat server, but I don't see a dbf/dbase driver, and
> > I can't find one either in the unixODBC home page.
> >
> > Alternatively, I could try to export the dbf to a text file (say,
> > csv), using something like the dbflist utility (part of the dbf2info
> > utilities; I've never used them, but I assume I can set them up!). The
> > MapServer document seems to imply that I could then set up an OVF to
> > link directly to flat text files without an ODBC DSN, but I can't find
> > any examples; I only see ODBC examples.
> >
> > Any advice on what's the easiest approach to accomplish this? Thanks!
>
> Emilio,
>
> The OVF mechanism can be used without ODBC.  In this case I would suggest
> you copy the .dbf file to a new name so it can be used in isolation
> via OVF as a spatial-data-less input file.  Then you would use normal
> OVF mechanisms, but instead of setting the SrcDatasource to an ODBC
> connection string, just give the path to the .dbf file.
>
> Best regards,

Thanks, Frank!! I got it to work on a Windows box with GDAL/OGR 1.2.5
(from FWTools 0.9.6). BTW, I think the MapServer or OGR documentation
regarding VRT access from file data sources (like this case) is
lacking. The ovf file I created is included at the bottom, with two
layers that correspond to two dbf files. The layer name is the base
file name of the dbf file, w/o the extension. The data source is the
path to the folder. Anything different I tried didn't work. I'll try
to edit the MapServer document "Virtual Spatial Data (ODBC/OVF)" to
include this example.

Now I have a different problem. I'm running MapServer 4.0 on a Linux
box with OGR 1.1.9. I read that OVF was introduced in OGR 1.2.0 (and
in fact, my ogr2ogr line can't handle the ovf file!). Given my old
MapServer, do you think it'd be safe to upgrade GDAL/OGR to the latest
version without upgrading MapServer (I don't want to deal with all the
dependencies just yet)?

Thanks. Cheers,

-Emilio

Accessing non-spatial tabular data from simple dbf files, through OVF:

<OGRVRTDataSource>
  <OGRVRTLayer name="hotspot48h">
    <SrcDataSource>/home/caee/mapache/data/fires</SrcDataSource>
    <GeometryField encoding="PointFromColumns" x="LONGITUDE" y="LATITUDE"/>
    <GeometryType>wkbPoint</GeometryType>
    <LayerSRS>WGS84</LayerSRS>
  </OGRVRTLayer>
  <OGRVRTLayer name="hotspot7d">
    <SrcDataSource>/home/caee/mapache/data/fires</SrcDataSource>
    <GeometryField encoding="PointFromColumns" x="LONGITUDE" y="LATITUDE"/>
    <GeometryType>wkbPoint</GeometryType>
    <LayerSRS>WGS84</LayerSRS>
  </OGRVRTLayer>
</OGRVRTDataSource>



More information about the MapServer-users mailing list