Appending to Shapefile Woes [message #81162] |
Thu, 23 August 2012 14:49 |
DavidF[1]
Messages: 94 Registered: April 2012
|
Member |
|
|
Folks,
Since I wasted a couple of good hours on this today, I thought I would note it for posterity. I have a new program, cgShapePointFile, that can write a shapefile filled with one or more points as individual entities. An arbitrary number of attributes can be associated with the points.
There was no trouble creating the initial file, but I wanted to be able to append points to this file, as needed. I ran into a interesting problem that took a while to solve. I was opening the file initially like this:
shapefile = Obj_New('IDLffShape', filename, /UPDATE, ENTITY_TYPE=1)
The UPDATE keyword opens the file for writing, and the ENTITY_TYPE
keyword opens it for point data. But, alas, if you open the file like
this when you are trying to append to the file, the "entities" in the
file get wiped out! When you try to find out how many entities are in
the file (so you can get the entity index for the appended entities
right), the file always reports zero entities!
The secret is to remove the ENTITY_TYPE keyword if you want to append
entities to the file:
; Open the shapefile for writing point data.
IF appending THEN BEGIN
shapefile = Obj_New('IDLffShape', filename, /UPDATE)
ENDIF ELSE BEGIN
shapefile = Obj_New('IDLffShape', filename, /UPDATE, ENTITY_TYPE=1)
ENDELSE
I didn't find this documented anywhere, obviously. :-)
Cheers,
David
|
|
|