[GIS] How to read Autodesk Spatial Data File (.SDF) in PHP

mapguidePHPsdf

I am working on an application using Autodesk MapGuide. The application is being developed on PHP and hosted in IIS 7.5.

I had to create point, line and polygon geometries on-the-fly. I found a working code sample and customized it for my logic. The sample writes the geometry in an SDF (Autodesk Spatial Data File) file. The code writes only three fields – ID, Text and Geometry. The ID field is "AutoIncrement"

Now, I have to store the remaining data about the feature drawn on map (and stored in SDF) into a table in MySQL. For that, I have to fetch the ID of the last entry into the SDF file, which is not exposed at any point. Also, I have to select a row in MySQL table based on the feature I select on map/drawing (whose geometry is stored in SDF file) for updates. For that also, I have to again read/query the SDF.

How can I achieve that using PHP?

Thanks

Best Answer

First of all: your original question is bad. You will may get inconsistensies if 2 users are using the file at the same time and your mysql server is suddenly responding slower or not at all, which may mean that properties are added to the wrong id.

It may therefore be better to add all data to mysql, including the spatial data. There is an FDO provider for mysql data, so you can add them to the map as well.

It is still possible to use a seperate sdf file, but in that case you should make sure that you don't read the file seperately from inserting the data. Luckily, this is possible: check where you use UpdateFeatures using an MgInsertFeatures object. In this case:

If the command is of type MgInsertFeatures, the property type is an MgPropertyType::Feature, and its value is a MgFeatureReader object. The feature reader object contains the set of properties inserted into the datastore by the insert command.

http://mapguide.osgeo.org/files/mapguide/docs/2.0/d5/d10/class_mg_feature_service.htm

You now discard the result of the UpdateFeatures function. Keep it and use it.