" +<BR> "parent.parent.Refresh(); "; //ClientScript.RegisterStartupScript(GetType(), "StartupKey", JavaScriptCall); Response.Write(JavaScriptCall); }"/>
Infrastructure Map Server Forum
Welcome to Autodesk’s Infrastructure Map Server Forums. Share your knowledge, ask questions, and explore popular Infrastructure Map Server topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trying to add a new Point in Session Layer - Not working

2 REPLIES 2
Reply
Message 1 of 3
anand_ganesh
691 Views, 2 Replies

Trying to add a new Point in Session Layer - Not working

Hello All,

I am trying to add a new Point to the Session Layer. Here is my code.

For some reason I am not seeing the point.

Any suggestions please ?

Thanks
Anand


private void DrawPoint(string InPointID, string InColorCode, string InX, string InY)
{
MgMap TheMapHandle = null;
MgResourceService TheResourceService = null;
MgFeatureService TheFeatureService = null;
string SessionString = "";
TheMapHandle = (MgMap)Session["TheMapHandle"];
TheResourceService = (MgResourceService)Session["TheResourceService"];
TheFeatureService = (MgFeatureService)Session["TheFeatureService"];
SessionString = Session["SessionString"].ToString();

//// Create a temporary feature source to draw the lines on
//// Create a feature class definition for the new feature
//// source
MgClassDefinition TheClassDefinition = new MgClassDefinition();
TheClassDefinition.SetName("Points");
TheClassDefinition.SetDescription("Redline Points");
string GeomPropName = "SHPGEOM";
TheClassDefinition.SetDefaultGeometryPropertyName(GeomPropName);

MgDataPropertyDefinition IdentityProperty = new MgDataPropertyDefinition("KEY");
IdentityProperty.Name = "KEY";
IdentityProperty.Description = "KEY Desc";
IdentityProperty.SetDataType(MgPropertyType.Int32);
IdentityProperty.SetAutoGeneration(true);
IdentityProperty.SetReadOnly(true);
TheClassDefinition.GetIdentityProperties().Add(IdentityProperty);
TheClassDefinition.GetProperties().Add(IdentityProperty);

MgDataPropertyDefinition NameProperty = new MgDataPropertyDefinition("NAME");
NameProperty.Name = "NAME";
NameProperty.Description = "NAME Desc";
NameProperty.SetDataType(MgPropertyType.String);
TheClassDefinition.GetProperties().Add(NameProperty);

MgGeometricPropertyDefinition GeometryProperty = new MgGeometricPropertyDefinition(GeomPropName);
GeometryProperty.SetGeometryTypes(MgFeatureGeometricType.Surface);
GeometryProperty.SetSpatialContextAssociation("spatial context");
TheClassDefinition.GetProperties().Add(GeometryProperty);

MgFeatureSchema TheMgFeatureSchema = new MgFeatureSchema("SHP_Schema", "Point schema");
TheMgFeatureSchema.GetClasses().Add(TheClassDefinition);

string TheFeatureSourceresourcestring = "Session:" + SessionString + "//Points.FeatureSource";
MgResourceIdentifier TheMgResourceIdentifierFeatureSource = new MgResourceIdentifier(TheFeatureSourceresourcestring);

string wkt = TheMapHandle.GetMapSRS();

MgCreateSdfParams TheMgCreateSdfParams = new MgCreateSdfParams("spatial context", wkt, TheMgFeatureSchema);
MgFeatureSourceParams TheMgFeatureSourceParams = TheMgCreateSdfParams as MgFeatureSourceParams;
TheFeatureService.CreateFeatureSource(TheMgResourceIdentifierFeatureSource, TheMgFeatureSourceParams);

MgBatchPropertyCollection batchPropertyCollection = new MgBatchPropertyCollection();
MgPropertyCollection PointPropertyCollection = new MgPropertyCollection();

MgStringProperty PointnameProperty = new MgStringProperty("NAME", InPointID);
PointPropertyCollection.Add(PointnameProperty);

MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
MgGeometry ThePointGeom = wktReaderWriter.Read("POINT XY (" + InX + " " + InY + ")");
MgByteReader TheGeomByteReader = agfReaderWriter.Write(ThePointGeom);
MgGeometryProperty ThePointProperty = new MgGeometryProperty("SHPGEOM", TheGeomByteReader);
PointPropertyCollection.Add(ThePointProperty);

batchPropertyCollection.Add(PointPropertyCollection);

// Add the batch property collection to the feature source
MgInsertFeatures TheMgInsertFeaturesCMD = new MgInsertFeatures("Points", batchPropertyCollection);
MgFeatureCommandCollection featureCommandCollection = new MgFeatureCommandCollection();
featureCommandCollection.Add(TheMgInsertFeaturesCMD);

// Execute the "add" commands
TheFeatureService.UpdateFeatures(TheMgResourceIdentifierFeatureSource, featureCommandCollection, false);

string ThePointXMLFileName = "C:\\Temp\\Anand\\RedlineToolPointLayer.LayerDefinition.xml";
XmlDocument TheXmlDocument = new XmlDocument();
TheXmlDocument.Load(ThePointXMLFileName);
XPathNavigator TheXPathNavigator = TheXmlDocument.CreateNavigator();

//XmlNamespaceManager TheXmlNamespaceManager = new XmlNamespaceManager(TheXPathNavigator.NameTable);
//TheXmlNamespaceManager.AddNamespace("bk", "http://www.contoso.com/books");
//foreach (XPathNavigator nav in TheXPathNavigator.Select("//bk:price", TheXmlNamespaceManager))

foreach (XPathNavigator nav in TheXPathNavigator.Select("//VectorLayerDefinition/ResourceId"))
{
this.LabelUserMessage.Text = this.LabelUserMessage.Text + "
" + nav.Value;
nav.SetValue(TheFeatureSourceresourcestring);
}

foreach (XPathNavigator nav in TheXPathNavigator.Select("//VectorLayerDefinition/FeatureName"))
{
this.LabelUserMessage.Text = this.LabelUserMessage.Text + "
" + nav.Value;
nav.SetValue("Points");
}

this.LabelUserMessage.Text = this.LabelUserMessage.Text + "
After Setting ...";
foreach (XPathNavigator nav in TheXPathNavigator.Select("//VectorLayerDefinition/ResourceId"))
{
this.LabelUserMessage.Text = this.LabelUserMessage.Text + "
" + nav.Value;
}


string xmlstring = TheXmlDocument.OuterXml;
this.LabelUserMessage.Text = this.LabelUserMessage.Text + "
xmlstring ..." + xmlstring;

System.Text.Encoding enc = System.Text.Encoding.GetEncoding("UTF-8");
byte[] TheLayerDefData = enc.GetBytes(xmlstring);


MgByteSource TheMgByteSource = new MgByteSource(TheLayerDefData, TheLayerDefData.Length);
TheMgByteSource.SetMimeType(MgMimeType.Xml);
string TheLayerresourcestring = "Session:" + SessionString + "//TemporaryPoints.LayerDefinition";
MgResourceIdentifier TheMgResourceIdentifierLayer = new MgResourceIdentifier(TheLayerresourcestring);
TheResourceService.SetResource(TheMgResourceIdentifierLayer, TheMgByteSource.GetReader(), null);


MgLayer ThePointLayer = new MgLayer(TheMgResourceIdentifierLayer, TheResourceService);
ThePointLayer.SetName("Points");
ThePointLayer.SetVisible(true);
ThePointLayer.SetLegendLabel("Redline Point Layer");
ThePointLayer.SetDisplayInLegend(true);

MgLayerCollection TheMapLayers = TheMapHandle.GetLayers();
if (DoesLayerExist(ThePointLayer.Name, TheMapHandle) == false)
{
TheMapLayers.Insert(0, ThePointLayer);
}

TheMapHandle.Save();


MgFeatureQueryOptions TheQueryOptions = new MgFeatureQueryOptions();
TheQueryOptions.SetFilter("");
MgLayerBase ThePointsLayer = TheMapHandle.GetLayers().GetItem("Points");
MgFeatureReader ThefeatureReader = ThePointsLayer.SelectFeatures(TheQueryOptions);
while (ThefeatureReader.ReadNext())
{
MgByteReader PointGeomByteReader = ThefeatureReader.GetGeometry("SHPGEOM");
MgAgfReaderWriter TheagfReaderWriter = new MgAgfReaderWriter();
MgGeometry CheckPointGeom = TheagfReaderWriter.Read(PointGeomByteReader);
this.LabelUserMessage.Text += "
The POINT Geom = " + CheckPointGeom.Centroid.Coordinate.X + ", " + CheckPointGeom.Centroid.Coordinate.Y;
}

//string JavaScriptCall = "";
//ClientScript.RegisterStartupScript(GetType(), "StartupKey", JavaScriptCall);
string JavaScriptCall = "";
//ClientScript.RegisterStartupScript(GetType(), "StartupKey", JavaScriptCall);
Response.Write(JavaScriptCall);
}
2 REPLIES 2
Message 2 of 3
sakkaku
in reply to: anand_ganesh

No errors or anything? 😞

Make sure the layer and feature definition are being saved correctly. You can use the /mapagent and Resource -> GetResourceContent. (The resource will be Session:sessionstringhere//Points.LayerDefinition) Once you have verified both are saving correctly; select from it via Feature -> SelectFeatures (you will just need to fill in the Resource and ClassName). You should get a list of whatever you inserted earlier. I ended up wasting the most time trying to get the coordinate system right, which was rather annoying.
Message 3 of 3
anand_ganesh
in reply to: anand_ganesh

Thank you for the reply.

I used the Scribble Sample and I was able to redo the complete Tool.

But now I have a different issue.

Is it possible to supress displaying the different colors in the snapshot ?

The Layer can show up but need to suppress the values beneath it.

Any suggestions please ?

Thanks
Anand

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report