Reputation: 33615
Forgive me ignorance on this. I'm using Geo Django's built in MultiPolygonField
to store region data. The data stored in the DB for that field looks like this...
0106000020E6100000010000000103000000010000000700000000000000003C1EC023000000E690504000000000000D414023000000E63353400000000000344740460000004CD34C400000000080314240460000004C60474000000000003A21408D00000098EE3E400000000000BE34C08D00000098483F4000000000003C1EC023000000E6905040
I would like to use the region data here: http://download.geofabrik.de/europe.html# but saves the data as a .poly
file that describes the extent of this region.
My question is, how do I convert the .poly
data here to match how MultiPolygonField describes it in the DB?
Upvotes: 2
Views: 776
Reputation: 4021
The value from the DB that you show is the Well Known Binary (WKB) format of a geometry. If you are using PostGIS, you can look at the same geometry in the Well Known Text (WKT) format, which is more human readable. Here is a query to show the WKB geometry you posted as WKT:
SELECT ST_AsEWKT('0106000020E6100000010000000103000000010000000700000000000000003C1EC023000000E690504000000000000D414023000000E63353400000000000344740460000004CD34C400000000080314240460000004C60474000000000003A21408D00000098EE3E400000000000BE34C08D00000098483F4000000000003C1EC023000000E6905040'::geometry)
To store a geometry in GeoDjango, you need to use one of the input formats that it acccepts see the Django documentation for GEOSGeometry and OGRGeometry.
So you need to write a parser to convert the coordinates you have in the .poly file to a format known to Django (such as WKT or geojson).
Here is an example on how to construct a multi polygon with the first few coordinates of the .poly data you linked. Notice that the last coordinate needs to be the same as the first to close the polygon.
poly = GEOSGeometry('MULTIPOLYGON(((-5.86333200 8.14347501, -6.70445600 7.47862301, -3.44929601 6.28074401, -3.08375301 3.08165901, -1.71378401 3.10939901, -5.86333200 8.14347501)))')
To store the geometry, you can pass the WKT data directly as input to your MultiPolygonField, or you can construct the poly
geometry object as in the example, and pass that to your field.
Upvotes: 2