[mapguide-users] cannot insert feature,give a favor
knife
ldk114 at gmail.com
Mon Aug 6 21:31:47 EDT 2007
hi,everyone
sorry ,my english is not goog.
this' insert feature' (update and delete can do)question has bothered
me two days.when i compiles the program with vs2005,no erro occurs. of
course the sdf can be writeable
i checked the polygon:isvalid()=true,isclosed()=true,IsEmpty() =false
but,when i checked the void ReleaseReader(MgPropertyCollection res,
MgFeatureCommandCollection commands) ,
i found that "res.GetItem(i).GetPropertyType()=9,that is
MgStringProperty not MgFeatureProperty(type= 12), so res.GetItem(i)
cannot be converted to MgFeatureProperty"
how can i do?
the following is part of my code(.net)
---------------------------------------------------------------------------------------------------------
MgGeometryFactory geoFac = new MgGeometryFactory();
MgLinearRingCollection LinearRingCollection = new
MgLinearRingCollection();
MgCoordinateCollection CoordinateCollection = new
MgCoordinateCollection();
String[] coods = this.TextBox1.Text.Split(',');
for (int i = 1; i <= Convert.ToInt16(coods[0])*2 ; i+=2)
{
double x = Convert.ToDouble(coods[i]);
double y = Convert.ToDouble(coods[i+1]);
MgCoordinate coordinate = geoFac.CreateCoordinateXY(x, y);
CoordinateCollection.Add(coordinate);
//MgPoint point = new
MgGeometryFactory().CreatePoint(coordinate);
}
MgLinearRing LinearRing =
geoFac.CreateLinearRing(CoordinateCollection);
CoordinateCollection.Clear();
LinearRingCollection.Add(LinearRing);
MgPolygon Polygon = geoFac.CreatePolygon(LinearRing, null);
//propertyCol.Add(new MgInt32Property("Autogenerated_SDF_ID",
11));
propertyCol.Add(new MgStringProperty("Name", "it's me"));
propertyCol.Add(new MgInt32Property("Key", 11));
propertyCol.Add(new MgStringProperty("Url", "me,too"));
//Polygon.
propertyCol.Add(new MgGeometryProperty("Data",
geometryReaderWriter.Write(Polygon)));
ftrCmdCol.Add(new MgInsertFeatures(lyrClass, propertyCol));
set_ResourceWriteAble(resoureId, resourceService); // set sdf
readonly=false
if (ftrCmdCol.Count >= 1)
{
ReleaseReader(ftrService.UpdateFeatures(resoureId,
ftrCmdCol, false), ftrCmdCol);
layerToSave.ForceRefresh();
map.Save(resourceService);
}
//-----------------------
private void ReleaseReader(MgPropertyCollection res,
MgFeatureCommandCollection commands)
{
if (res == null)
return;
for(int i = 0; i < res.GetCount(); i++)
{
MgFeatureCommand cmd = commands.GetItem(i);
if(cmd is MgInsertFeatures)
{
if (res.GetItem(i).GetPropertyType() !=
MgPropertyType.Feature)
//res.GetItem(i).GetPropertyType()=9,that is
MgStringProperty not MgFeatureProperty(12)
//so res.GetItem(i) cannot be converted to
MgFeatureProperty
// does that mean the inserting action is failed?
return;
MgFeatureProperty resProp =
(MgFeatureProperty)res.GetItem(i);
if(resProp != null)
{
MgFeatureReader reader
=(MgFeatureReader)resProp.GetValue();
if(reader == null)
return;
reader.Close();
}
}
}
}
--
View this message in context: http://www.nabble.com/cannot-insert-feature%2Cgive-a-favor-tf4227545s16610.html#a12027085
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list