[Gdal-dev] OGRMySQL Connection

Mateusz Loskot mateusz at loskot.net
Sat Aug 11 14:01:06 EDT 2007


yohanes setiawan wrote:
> Hi,
> 
> I have read the documentation about ogrmysql connection in
> http://mapserver.gis.umn.edu/docs/howto/ogrmysql, which is define
> point data. I want to know if ogrmysql connections also available to
> define a polygon data? If the answer is yes, can you give me guidance
> to do it? is there anything that I must provide, or maybe there's
> anything that you consider important related with the subject?

First, you should be aware of the idea behind the example you're
referring to.
The tutorial takes two important assumptions:
1) geometry data is of type of point
2) geometry data is not stored in single field (using GIS capabilities
offered by MySQL) but point coordinates are stored in
separate columns: x, y

These assumptions imply that OGR generates points on-fly from
data fetched from two separate columns.

Now, if you want to work with more complex data, line or polygon
then you likely will need to use GIS features of MySQL (or PostGIS, etc.).

This means, your polygons will be stored in single column
and you will be able to retrieve them as data encoded in WKT or WKB
formats. For instance:

1) fetch polygons as Well-Known-Text

SELCT AsText(geom) FROM mytable

2) fetch polygons as Well-Known-Binary

SELCT AsBinary(geom) FROM mytable

Now, compare these SQL queries to the one used in the tutorial.
You see, now we have geometry data stored in single column.

It results in next assumption that you don't have to tell OGR to compose
geometry object with data fetched from separate columns, but you have to
tell OGR to only fetch geometry data from geometry column.

Here, you can learn how to do it, especially section "GeometryField":

http://www.gdal.org/ogr/drv_vrt.html


Roughly, your VRT file will look like this:

...
   <SrcSQL>SELECT AsBinary(geom) FROM testdata</SrcSQL>
   <GeometryType>wkbPolygon</GeometryType>
   <GeometryField encoding="WKB" field="geom"/>
...

In the drv_vrt.html document, you can read why encoding is WKB and
how it works.

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Gdal-dev mailing list