Skip to main content
Solved

wkt: No attributes in inspector and in writer

  • July 11, 2017
  • 4 replies
  • 74 views

dollargis
Contributor
Forum|alt.badge.img+6

I try to read a csv-file, that contains geometries in wkt as well as attributes and want to convert these in a shapefile.

The first two lines look as follows:

WKT,fid,objectid,y,bt_nummer,flaeche_qm,name_stat_,x,shape_area,shape_len

 

MultiPolygon(((4469285.3 5337544.1, 4469292.1 5337435.9, 4469311.4 5337437.0))),1,10,5336470.71,12.4,1297528.91423,Münchener Freiheit,4469371.47,,

(note that I have shortened and cut the vertices)

There are two problems arising:

  1. The inspector doesn't show the attributes at all
  2. The shapefile writer (connected directly) gives only empty - but correctly named - columns in the attribute table

What am I missing?

Best answer by jdh

One issue you might find is that if you try and read the csv directly, the multipolygon coordinates are also separated by a comma, and would be become different columns. Putting quotes around it solves that problem.

 

 

Otherwise I don't see a real issue, other than ensuring the encoding is correct.

 

csvwkt.fmwt
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

erik_jan
Contributor
Forum|alt.badge.img+23
  • Contributor
  • July 11, 2017

A few questions arise:

Did you set the CSV reader to have field names on the first row?

Did you convert (GeometryReplacer) the WKT attribute to a geometry?

Are the Shape attributes exactly the same as the CSV attributes (case sensitive)?


jdh
Contributor
Forum|alt.badge.img+40
  • Contributor
  • Best Answer
  • July 11, 2017

One issue you might find is that if you try and read the csv directly, the multipolygon coordinates are also separated by a comma, and would be become different columns. Putting quotes around it solves that problem.

 

 

Otherwise I don't see a real issue, other than ensuring the encoding is correct.

 

csvwkt.fmwt

dollargis
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • July 11, 2017

One issue you might find is that if you try and read the csv directly, the multipolygon coordinates are also separated by a comma, and would be become different columns. Putting quotes around it solves that problem.

 

 

Otherwise I don't see a real issue, other than ensuring the encoding is correct.

 

csvwkt.fmwt
@jdh: Thanks for the example code that greatly helped me a big step further. It turned out the missing quotes were causing that error. Now that I have changed my csv-file accordingly, both geometry and attributes get imported.

 

 

However - all attributes get imported as strings, in spite of me providing a csvt-file, indicating the correct data types!

 

 

As far as my research goes, this is a known problem with the ogr 1.x version library. I have imported my files successfully with ogr2ogr v. 2.x, but unfortunately this is not an option in my current project.

 

 


dollargis
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • July 11, 2017

A few questions arise:

Did you set the CSV reader to have field names on the first row?

Did you convert (GeometryReplacer) the WKT attribute to a geometry?

Are the Shape attributes exactly the same as the CSV attributes (case sensitive)?

@erik_jan_: I thought I had done those first two points correctly, but it turned out the quotes were missing. Re. the shape attributes: I want to create the shape dynamically - and it turns out that there is still a problem with the data types ahead.