I'm not sure if this issue lies within the shp2sql code or my shapefile itself, but I get an undefined geotype error when importing a shapefile containing linestrings. This shapefile was created using arcgis, and also renders fine in qgis (and I tried a version of the file which was re-exported from qgis). Basically, the first 2 lines are read with the correct geo type index (3), but then the bytes are somehow shifted out of order, and I get a large negative number (-1806811483) for the geotype index.
I'm merely posting this here to see if other people have run into the same issue; I'm not really sure which direction to continue investigating in at this point.
Also, I am unfortunately unable to post my shapefile due to NDA restrictions.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | shp2sql.inc_.txt | 10.43 KB | apolzon |
Comments
Comment #1
allie mickaI'm thinking that this may be related to http://drupal.org/node/429256 - Bec patched the code in geo.wkb.inc , but the same treatment should probably be applied to the shp2sql code.
Comment #2
phayes commentedI ran into this issue before and can confirm that this is an issue with shapefile parsing in shp2sql.inc
Comment #3
phayes commentedComment #4
apolzon commentedThis issue still exists in 6.x-1.0-alpha2. I looked into applying the wkb changes to the shp2sql file, but my attempts all ended in failure; admittedly I don't know a ton about how to properly use unpack and byte_order.
Comment #5
apolzon commentedA coworker and I (scottschulthess, at OHO Interactive) were able to update shp2sql.inc and successfully import both polylines and polygons. The bulk of the clues we found were from this article: http://www.easywms.com/easywms/?q=zh-hant/node/78
Here are the things I believe we changed:
1. _shp_get_linestring was not pulling the numparts (4 bytes) out of the file, so the bytes were off when loading a polyline into the database. This was causing the geo_type to come up as unsupported. (I'm not sure if a polyline/linestring can ever have more than one numpart, so right now we're assuming its only one)
2. The unpack parameter 'i' was changed to 'V'. 'i' is machine-dependent, but 'V' will always read in little endian byte-order.
3. in _shp_get_linestring, the wkt is built but never added to the $data array which is returned. This results in a null geo object.
4. There seems to be some issue with the way the unpack method is used in a couple places. in _shp_get_linestring, it pulls 4 8-byte elements from the file (as one 32 byte segment). When we changed this to 4 separate 8-byte reads, we were able to successfully import. I don't really understand the difference between what we wrote and what was already there, so I've pasted it here in case anyone has any ideas:
Original: (broken)
Original (patched): (also broken)
New code: (working)
loadData func:
I've uploaded our modified shp2sql.inc and would be happy to commit it to CVS if the maintainer approves.
Comment #6
apolzon commentedI've also just realized that 'd' is also a machine-dependent format specifier. If anyone is on a different architecture (powerpc most likely) and having issues, I'd try using 'V' in place of 'd'.
Comment #7
apolzon commentedChanging status to needs review
Comment #8
allie mickaThere are now 3 issues that suggest similar problems. Please try and see if there is already a similar issue before filing a new one - that saves everyone a lot of time!
alpozon, thanks for your patches and followup! I am referring #483094: Geospatial data - Cannot import Shapefiles and #394678: Geospatial Data - Shapefile import here. Technically, _this_ issue is probably a duplicate of those, but I have selected the issue with the most input to be the main one.
Thanks!
Comment #9
allie mickaThanks apolzon,
After revisiting the specfications and fixing up some obvious code issues, I was able to get the linestring data working properly. I suspect that Endian-ness is still an issue. It may be necessary to revisit bec's work in #429256 for this functionality.
Comment #11
khalligan commentedI am having this issue as well. I downloaded the modified version of shp2sql.inc from apolzon but this did not solve the problem. I am receiving the following error:
"Unsupported geo type found in file."
When I try to upload a shapefile with polyline data type created in ArcGIS. Point and Polygon shapefiles work fine. I am running Ubuntu 8.10 (intrepid) on an Intel based virtual server, so I don't believe it is an endian issue.
Comment #12
blattmann commentedThe fix suggested in #5 doesn't seem to make a difference for me, and uploading a polyline continue to result in the error Unsupported geo type found in file.
Any ideas?