Opened 17 years ago
Last modified 17 years ago
#2014 new enhancement
layerObj.getFeature seems to return a copy not a reference
Reported by: | Owned by: | sdlime | |
---|---|---|---|
Priority: | high | Milestone: | FUTURE |
Component: | MapScript | Version: | 4.10 |
Severity: | minor | Keywords: | |
Cc: |
Description
Using MapScript 4.10 on windows layerObj.getFeature seems to return a copy, not a reference. I call getFeature and change the annotation on the feature. I can see that the text property changes. I then call getFeature again with the same index and I get a feature with the original annotation. I updated a copy. It would be nice to get a real reference so I can edit the feature, would also be nice to have a method for removing features.
Change History (5)
comment:2 by , 17 years ago
A reference directly to a feature in a shapefile or database isn't possible. You always end up working with a copy and then would need to somehow commit your changes. MapServer hasn't gone that far and probably won't in the near future. Basically each driver would need to support an update method and the presents a number of challenges. For example, it is probably possible to edit the attrubutes of a shapefile in place, but you can't do that on the spatial side. You must re-write the whole file in that case. Note that you often have the tools to do this outside of MapServer within the scripting language now. Marking as something to look at in the future. Steve
comment:3 by , 17 years ago
[FURTHER EXPLANATION] I'm working with inline features defined in the mapfile. I don't believe the layer feature collection gives access to shapefile or database features. layerObj.addFeature layerObj.getNumFeatures layerObj.getFeature seem to work together and refer specifically to INLINE features. getNumFeatures throws "msLayerGetNumFeatures(): Shapefile error. Not an inline layer" if the layer is not an inline layer. addFeature works, and added features are displayed on the map. I'm not looking to edit the map file by editing a feature, just to modify what is displayed on the map for an inline feature. [RESPONSE FROM STEVE] I didn't realize you were talking inline features only. getFeature works for all connection types which makes it difficult to do what you're asking. Only addFeature is limited to inline layers. getNumFeatures only works for inline layers but that's because other drivers haven't registered an equivalent.
comment:4 by , 17 years ago
In fact mapserver handles the various data providers uniquely the returned shapeObj-s are owned by the caller who is responsible to destroy the shapes. The various drivers normally does not retain or cache the shapeObj-s so retrieving the shape by reference was not too relevant except for the inline layers. However since I'm thinking of an addition that would provide a feature cache for the various data providers this problem also gets some actuality. The long running processes being capable to maintain the state of the mapscript objects would happy to have a possibility to modify these shapes occasionally. To provide some solution it would be desirable to make an additional function like layer.GetShapeRef() in the layerObj vtable. This function would return the shapes by reference and the caller would not destroy the underlying shape. Tamas
comment:5 by , 17 years ago
Cc: | added |
---|
Note:
See TracTickets
for help on using tickets.