2

I've recently received some parcel data in shapefile format that has z & m coordinates (all = 0.0). The WKT for a typical parcel looks like this:

"MULTIPOLYGON (((2672464.560700002 711396.4336998622 0.0 0.0, 2672428.060700002 711369.2463998601 0.0 0.0, 2672373.310000001 711454.3723998595 0.0 0.0, 2672410.0600000033 711481.4969998623 0.0 0.0, 2672464.560700002 711396.4336998622 0.0 0.0)))"

This data is not being accepted by my ruby gis program/libraries (rgeo) when I try to parse the WKT. I could use gdal/grass (little to no experience), Python (little to no experience) or some other ruby library, but I'd prefer to sanitize this code of its 3D (Z) and M coordinates using qgis.

Given the fact that this question has been unanswered for days ANY solution would be appreciated, including grass, gdal, other ruby libraries, python, even arcgis (I have a new PC so can do a new 30 day trial...)

  • It looks like you have M coordinates in there as well. – DPierce Oct 30 '13 at 19:33
  • 2
    You might try the Copy Features tool in ArcGIS and in the environment settings disable 3D and M. In QGIS you might see if copying and pasting features into a new shapefile layer loses the 3D and M information, although that may require too much related work if you have a lot of layers or fields. Maybe you could append these parcels to a 2D layer, and then remove the pre-existing? – johns Nov 1 '13 at 13:21
  • 1
    You probably want to talk to your data provider as well, since the files you have received are not in Well-Known Text format (if they were, they'd be "MULTIPOLYGON ZM"). – Vince Nov 1 '13 at 14:06
5
+50

For GDAL:

It looks like you can specify the output type when creating polygons using the SHPT option (see the docs for the shapefile driver). So you can specify if you want a simple 2d representation or 3d.

So in ogr2ogr:

ogr2ogr -lco SHPT=POLYGON -f "ESRI Shapefile" output_shapefile.shp input_shapefile.shp

This should work if your parcel data is polygons.

| improve this answer | |
  • The shapes are all multipolygons. Most are like this ([polygon]) but some are actually multipolygons ([polygon1, polygon2])...would the solution work with them? (On the road right now can't test) – boulder_ruby Nov 1 '13 at 13:58
  • 1
    Shapefiles don't make a distinction between polygon and multipolygon. – Vince Nov 1 '13 at 14:07
  • As Vince says, this shouldn't be an issue. If you are loading it to a PostGIS database later on, you can at that point specify if it is a multi-part or not. – HeikkiVesanto Nov 1 '13 at 14:55
  • Knights of Columbus it worked! Well done!!! – boulder_ruby Nov 2 '13 at 18:54
  • 1
    - had to download KyngChaos's version of gdal, and add the /Library/Frameworks/GDAL.framework/Versions/1.10/Programs/ directory to my PATH in ~/.bash_profile to get the ogr2ogr command to fire in the 'ol terminal (Mac OSX) – boulder_ruby Nov 2 '13 at 18:55
3

You can work around the incorrect WKT formatting with sed (or any regular expression substitution app you have available):

cat invaildWKT | sed 's/ 0.0 0.0//g' > validWKT
| improve this answer | |
0

For QGIS... One 'hacky' workaround is to make a scratch layer, Clip it by your target layer, do a Multipart-to-Singlepart process, then generate your WKT. Since it's been clipped from the 2D layer in QGIS you can then re-render your WKT and it will only have Lat/Long. Finally, if needed, you can Spatial Join your original attributes to that result from your original target layer so that you have whatever those attributes were plus the new desired-format WKT.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.