Reading the node coordinates of linear features through the map 3D API

Source: Internet
Author: User
Tags polyline

by Daniel Du

In map 3D, you can use the Create from Geometry command to convert AutoCAD entities into FDO features in map 3D, such as converting AutoCAD polyline to FDO linear features.

For AutoCAD polyline that contain only lines, after the FDO feature is turned, it is a Mgcurvestring object and contains only one linearsegment.

If an arc arc is included in AutoCAD Polyine, the converted Fdo feature object will be a Mgcurvestring object that contains multiple segment. There are arc segment and linear segment.

Here is the code that reads the coordinate points for such a linear feature:

usingSystem;
usingAutodesk.AutoCAD.Runtime;
usingAutodesk.AutoCAD.ApplicationServices;
usingAutodesk.AutoCAD.DatabaseServices;
usingAutodesk.AutoCAD.Geometry;
usingAutodesk.AutoCAD.EditorInput;
usingAutodesk.Gis.Map.Platform.Interop;
usingAutodesk.Gis.Map.Platform;
usingOsgeo.mapguide;

//This line isn't mandatory, but improves loading performances
[Assembly:Commandclass(typeof(Getfeaturetype.Mycommands))]

namespaceGetfeaturetype
{

PublicclassMycommands
{


//Modal Command with localized name
[Commandmethod("Getpolylinecoordinates")]
Public voidMyCommand ()//This method can has any name
{
Editored = Autodesk.AutoCAD.ApplicationServices.Application
. DocumentManager.MdiActiveDocument.Editor;

Transactiontrans = Autodesk.AutoCAD.ApplicationServices.Application
. DocumentManager.MdiActiveDocument.Database.TransactionManager
. StartTransaction ();

using(trans)
{
//Get the Map Object
AcmapmapCurrentmap =Acmapmap. Getcurrentmap ();

//Prompt user to Select Feature in Map
promptselectionoptionsPsop =Newpromptselectionoptions();
Psop. Messageforadding ="Select the FDO Feature in Map 3D to read Data:";
Psop. Singleonly =true;
PromptselectionresultPsresult = ed. GetSelection (PSOP);

if(Psresult.status = =Promptstatus. OK)
{
SelectionsetSelset = Psresult.value;

//Get Map selectionset from AutoCAD selectionset
MgselectionbaseMapselbase =Acmapfeatureentityservice
. GetSelection (Selset);
AcmaplayerMaplayer =Acmapfeatureentityservice
. Getlayer (Psresult.value[0]. OBJECTID);

//get the ID of the selected Parcel
MgfeaturereaderFtrrdr = Mapselbase.getselectedfeatures (
Maplayer, Maplayer.featureclassname,false);

while(Ftrrdr.readnext ())
{
mgclassdefinitioncd = Ftrrdr.getclassdefinition ();

//the Geomety Property name maybe different for your
//data Source
MgbytereaderByterdr = Ftrrdr.getgeometry ("Geometry");
MgagfreaderwriterWTR =NewMgagfreaderwriter();

MggeometryGeom = WTR. Read (BYTERDR);

if(Geom isOsgeo.mapguide.mgcurvestring)
{
varCS = Geom asmgcurvestring;

Ed. Writemessage ("\ n Geo is mgcurvestring.");

for(inti = 0, Segmentcount = cs. Count; i < Segmentcount; i++)
{
varSEG = cs. GetSegment (i);
if(SEG ismgarcsegment)
{
Ed. Writemessage ("\nthis is an ARC Segment.");
varARCSEG = seg asmgarcsegment;

stringmsg =string. Format (
"\nstart point:x= {0}, y={1}",
Arcseg.startcoordinate.x,
ARCSEG.STARTCOORDINATE.Y);
Ed. Writemessage (msg);

msg =string. Format (
"\ncontrol point x= {0}, y={1}",
Arcseg.controlcoordinate.x,
ARCSEG.CONTROLCOORDINATE.Y);
Ed. Writemessage (msg);

msg =string. Format (
"\nend point:x= {0}, y={1}",
Arcseg.endcoordinate.x,
ARCSEG.ENDCOORDINATE.Y);
Ed. Writemessage (msg);
}
if(SEG ismglinearsegment)
{
Ed. Writemessage ("\nthis is a linear Segment.");

varLINEARSEG = seg asmglinearsegment;
varInterator = Linearseg.getcoordinates ();
while(Interator. MoveNext ())
{
varx = Interator. GetCurrent (). X
vary = interator. GetCurrent (). Y

Ed. Writemessage (string. Format (
"\ n x = {0}, y={1}", x, y));
}
}

}
}
if(Geom isOsgeo.mapguide.mglinestring)
{
varls = Geom asmglinestring;
varInterator = ls. Getcoordinates ();
while(Interator. MoveNext ())
{
varx = Interator. GetCurrent (). X
vary = interator. GetCurrent (). Y

Ed. Writemessage (string. Format (
"\ n x = {0}, y={1}", x, y));
}

}

}
}
Trans.commit ();
}

}



}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.