Geospatial operations on shapefile created with pyShp

153 views
Skip to first unread message

Mike T

unread,
Aug 28, 2012, 4:51:32 PM8/28/12
to geospati...@googlegroups.com
Hi,

I'm hoping someone can point me in the right direction.  I've got a rather large point shapefile that I created using pyShp 1.1.4, with 6 attribute fields.  4 of the fields are defined as "double", and hold floating point values.  The shapefile seems to write correctly, and can be opened in ArcGIS 10 sp5.  However, whenever I perform apply a geospatial tool to that dataset, the resulting shapefile (or gdb) converts the floating point values to integers.  Well, I don't know if an actual integer conversion is being performed, but the values themselves are truncated.

For example, two of the fields in the larger dataset are Lat and Lon, and hold values like -75.416.  But after clipping/selecting/exporting the value becomes -75.  The field is *still* defined as double, but obviously the data is lost.

This behavior is exhibited using the Clip tool, the "Copy Features" tool, and the drag-a-box-around-some-points selection tool (followed by create layer from selection).

I've tried this on two different machines, as well, and I don't get this behavior with other datasets. 

Here's the code I'm using:

w = shapefile.Writer(shapefile.POINT)
w.field('Lon','N','12')

.
.
for x in y:
#this is how I'm writing out
w.record(float(lonval))


w.save('C:\\myfolder\\myfile")

Any thoughts???

Thanks,
Mike



Joel Lawhead

unread,
Aug 28, 2012, 5:24:51 PM8/28/12
to geospati...@googlegroups.com, mikethe...@gmail.com
Mike,

When you create the Dbf field change the "N" for number (integer) to "D" for double (decimal).

> w.field('Lon','D','12')

When ArcGIS sees the "N" it is probably casting the coordinate to an integer.

When I created the pyshp documentation I took the lazy route and didn't include anything that's in the shapefile or Dbf spec. Eventually I'll get around to creating examples for common issues like this.

Let us know of that doesn't work and thanks for using pyshp.

- Joel


--
Joel Lawhead, PMP
NVision Solutions Inc.
Web: http://www.nvs-inc.com

Mike T

unread,
Aug 28, 2012, 5:44:57 PM8/28/12
to geospati...@googlegroups.com
Ok - thanks.  I'll try that.  I figured if the number had been cast as an integer from pyShp, the decimal values (all those to the right of the decimal point) would never have showed up when I opened in ArcGIS.  And they did, which made me think I was doing things properly.

I may try some other voodoo, and see if I can get it to work before rewriting the file.  It took me about 12 hours, and that's using parallel python cooking on 8 cores.  So, I'd like to avoid starting over :-)

Either way - hopefully changing to "D" will fix the issue.

thanks,
mike
Reply all
Reply to author
Forward
0 new messages