[mapguide-users] Re: Add geometry to feature source
Greg
gbneff at cid.utah.gov
Tue Mar 8 17:59:21 EST 2011
Thanks for pointing me in the right direction. I am much closer now but
still have a problem:
After creating the feature source and adding the features I use an
MgFeatureReader to see if things have actually been added and the reader has
no rows. I have probably done something wrong with the MgInsertFeatures
command but I can't figure out what. My code is below. If you have a
minute, please take a look.
Thanks,
Greg
//create lines using the coordinates from the file
for (i = 0; i < lat.Count - 1; i+=2)
{
//convert from Lat Lon to X Y
coordLatLon =
geometryFactory.CreateCoordinateXY(Convert.ToDouble(lon[i]),
Convert.ToDouble(lat[i]));
coordXY = mapCS.ConvertFromLonLat(coordLatLon);
coordsXY.Add(coordXY);
coordLatLon =
geometryFactory.CreateCoordinateXY(Convert.ToDouble(lon[i+1]),
Convert.ToDouble(lat[i+1]));
coordXY = mapCS.ConvertFromLonLat(coordLatLon);
coordsXY.Add(coordXY);
line = geometryFactory.CreateLineString(coordsXY);
geometries.Add(line);
coordsXY.Clear();
//X.Add(coordXY.GetX().ToString());
//Y.Add(coordXY.GetY().ToString());
//if (i < 108)
//{
// Response.Write("
" + line.GetLength().ToString() + "");
//}
}
MgMultiGeometry mergedFeatures;
mergedFeatures = geometryFactory.CreateMultiGeometry(geometries);
MgPropertyCollection properties = new MgPropertyCollection();
MgAgfReaderWriter agfRW = new MgAgfReaderWriter();
MgByteReader agfByteStream;
agfByteStream = agfRW.Write(mergedFeatures);
MgGeometryProperty geometryProperty;
geometryProperty = new MgGeometryProperty("curveProp",
agfByteStream);
properties.Add(geometryProperty);
MgInsertFeatures insertCommand;
insertCommand = new MgInsertFeatures("curveInsert", properties);
MgFeatureCommandCollection commands = new
MgFeatureCommandCollection();
commands.Add(insertCommand);
//TODO: ***** check if TruckRoute feature class already exists *****
MgClassDefinitionCollection featClassColl = new
MgClassDefinitionCollection();
//create feature source
//create feature class definition
String geomPropName = "curveGeom";
MgClassDefinition featClass = new MgClassDefinition();
featClass.SetName("truck_route");
featClass.SetDescription("Truck Route Display");
featClass.SetDefaultGeometryPropertyName(geomPropName);
MgPropertyDefinitionCollection classProperties =
featClass.GetProperties();
//create identity property
MgDataPropertyDefinition idProp = new
MgDataPropertyDefinition("featId");
idProp.SetDataType(MgPropertyType.Int32);
idProp.SetAutoGeneration(true);
idProp.SetReadOnly(true);
classProperties.Add(idProp);
//create geometry property
MgGeometricPropertyDefinition curveProp = new
MgGeometricPropertyDefinition(geomPropName);
curveProp.SetGeometryTypes(MgFeatureGeometricType.Curve);
curveProp.SetHasElevation(false);
curveProp.SetHasMeasure(false);
curveProp.SetSpatialContextAssociation("defaultSrs");
classProperties.Add(curveProp);
MgPropertyDefinitionCollection idProps =
featClass.GetIdentityProperties();
idProps.Add(idProp);
//create a feature schema
MgFeatureSchema curveSchema = new MgFeatureSchema();
curveSchema.SetName("Schema1");
curveSchema.SetDescription("temp schema for truck_route");
curveSchema.GetClasses().Add(featClass);
//creat sdf parameters
MgCreateSdfParams sdfParams = new MgCreateSdfParams();
sdfParams.SetSpatialContextName("defaultSrs");
sdfParams.SetCoordinateSystemWkt(srsMapDef);
sdfParams.SetFeatureSchema(curveSchema);
//add feature source to feature service
MgResourceIdentifier TruckRouteFeatureResId = new
MgResourceIdentifier("Session:" + sessionId +
"//truck_route.FeatureSource");
featureService.CreateFeatureSource(TruckRouteFeatureResId,
sdfParams);
featureService.UpdateFeatures(TruckRouteFeatureResId, commands,
false);
//check features created
MgFeatureQueryOptions nameQuery = new MgFeatureQueryOptions();
nameQuery.SetFilter("featId = 0");
MgFeatureReader featureReader =
featureService.SelectFeatures(TruckRouteFeatureResId, "truck_route",
nameQuery);
while (featureReader.ReadNext())
{
Response.Write("
featId = " + featureReader.GetInt32("featId").ToString() + "");
}
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Add-geometry-to-feature-source-tp6082938p6148410.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list