add features to map

add features to map

Anonymous
Not applicable
1,766 Views
8 Replies
Message 1 of 9

add features to map

Anonymous
Not applicable

i am new to autocad map3d . i want to add feature from sqlite database to map3d  in c# to edit them ,i create connection by code below but i dont know how add it to map!! can anyone help me?

OSGeo.FDO.IConnectionManager connManager = FeatureAccessManager.GetConnectionManager();
IConnection conn = connManager.CreateConnection("OSGeo.SQLite");
conn.ConnectionInfo.ConnectionProperties.SetProperty("ReadOnly", false.ToString());
string fileName = @"KaisMapData.sqlite";
conn.ConnectionInfo.ConnectionProperties.SetProperty("File", fileName);
conn.Open(); 

0 Likes
1,767 Views
8 Replies
Replies (8)
Message 2 of 9

fieldguy
Advisor
Advisor
Message 3 of 9

Anonymous
Not applicable

thanks for reply

i use fdo connection and it works but dosent show in map .my problem is showing on map in map3d

m

0 Likes
Message 4 of 9

fieldguy
Advisor
Advisor

>>i use fdo connection and it works but dosent show in map<<

You do not show any code that actually adds features.  If you use CTRL-A (select all) in autocad, are any objects selected?  Also, use quick select in Properties dialog.  Any objects?

If you are importing points, they may be hard to see.  Try PDMODE and PDSIZE (if you are trying to importing points as points - not blocks).

0 Likes
Message 5 of 9

norman.yuan
Mentor
Mentor

Firstly, by saying "...to add feature from sqlite database to map3d...", I assume you mean add feature into Acad Map VISUALLY, as map layer, just as you do it manually by opening "Data Connections" Palette, choosing a FDO provider, and and following the process... until the FDO data is retrieved from FDO source and shows up in Acad Map as a map layer.

 

Yes, you can use only FDO API to access (read and/or write) FDO source from Acad Map (as your partial code showed). However, with FDO API only, you only read the data into ACAD Map's memory. You can do whatever you wish with the data in memory (say, you can convert the geometries into native AutpCAD entities, line, circle, polyline... (thus visually appear in Acad), but the FDO data do not becomes Acad Map layer just because of being retrieved by FDO API. In order to do that, you need to use Acad Map geospatial platform API, which is built on top of FDO API.

 

It would be quite easy to get going by simply browsing some sample codes from Autodesk. If you haven't, download AutoCAD Map ObjectARX SDK (not that you must have it in order to write code, you don't), download it (any Acad Map version is fine), unzip it into any where in you drive, go to the folder "...\Map Samples\Platform", a lot of code samples on  Acad Map geospatial platform API. The solution "BuildMap" is exactly what you want to see.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 6 of 9

Anonymous
Not applicable

thank you

i use this sample and now i can add sqlite connection but still i cannot add it to map .it say "it say out of index bounds" my code is here:

 

OSGeo.FDO.IConnectionManager connManager = FeatureAccessManager.GetConnectionManager();
IConnection conn = connManager.CreateConnection("OSGeo.SQLite");
conn.ConnectionInfo.ConnectionProperties.SetProperty("ReadOnly", false.ToString());
string fileName = @"KaisMapData.sqlite";
conn.ConnectionInfo.ConnectionProperties.SetProperty("File", fileName);
ConnectionState connState = conn.Open();
ed.WriteMessage("connect status is " + connState.ToString() + "\n");

MgResourceService rs;
rs = AcMapServiceFactory.GetService(MgServiceType.ResourceService)
as MgResourceService;
MgFeatureService fs;
fs = AcMapServiceFactory.GetService(MgServiceType.FeatureService)
as MgFeatureService;
MgResourceIdentifier fsId = new MgResourceIdentifier(
"Library://gis_osm_buildings_a_free_1.FeatureSource");

// Create the feature source definition with a required
// parameter of File and an optional parameter of ReadOnly

string xmlString;
FeatureSourceType fsType = new FeatureSourceType();

fsType.Provider = "OSGeo.SQLite";

NameValuePairType param = new NameValuePairType();
param.Name = "File";
param.Value = @"C:\Users\OmraniS\Desktop\gis_osm_buildings_a_free_1.sqlite";
NameValuePairType param2 = new NameValuePairType();
param2.Name = "ReadOnly";
param2.Value = "True";
fsType.Parameter = new NameValuePairType[] { param, param2 };

// Serialize the feature source object model to xml string
using (StringWriter writer = new StringWriter())
{
XmlSerializer xs = new XmlSerializer(fsType.GetType());
xs.Serialize(writer, fsType);
xmlString = writer.ToString();
}

// Convert the Unicode string to UTF8 bytes for Resource Service

byte[] unicodeBytes = Encoding.Unicode.GetBytes(xmlString);
byte[] utf8Bytes = Encoding.Convert(Encoding.Unicode,
Encoding.UTF8, unicodeBytes);

// Create a byte reader containing the XML feature
// source definition. Store the definition in the repository

MgByteSource xmlSource = new MgByteSource(utf8Bytes,
utf8Bytes.Length);
rs.SetResource(fsId, xmlSource.GetReader(), null);

IDescribeSchema descSchemaCmd = conn.CreateCommand(CommandType.CommandType_DescribeSchema) as IDescribeSchema;
FeatureSchemaCollection fsc = descSchemaCmd.Execute();
FeatureSchema schema = fsc[0];
MessageBox.Show((schema.Classes.IndexOf("@Default")).ToString());
ClassDefinition classDef = schema.Classes[schema.Classes.IndexOf("@Default")];

MessageBox.Show(fsId.ToString());
MessageBox.Show(rs.ToString());
MgLayerBase layer = AcMapLayer.Create(fsId,rs);

layer.SetName("NewLayer");
AcMapMap currentMap = AcMapMap.GetCurrentMap();
currentMap.GetLayers().Add(layer);

}

0 Likes
Message 7 of 9

Anonymous
Not applicable

Im working on the same issue..trying to make a SHP feature connection. But i have problem with a missing reference. I have the code

 

FeatureSourceType fsType = new FeatureSourceType();

 

Anyone knows with dll I need?

0 Likes
Message 8 of 9

norman.yuan
Mentor
Mentor

To do AutoCAD geospatial (formerly called Platform) programming, the code needs to deal with FeatureSourceSchema and LayerDefinitionSchema. You can generate source code with MS' xsd.exe against the schemas provided the SDK (in folder "...\[SDK folder]\Schema\". To simply this work, the SDK also provides the source code in "...\[SDK folder]\Map Samples\Platform\Schema\", where there are 2 c# code file: FeatureSource-1_0_0.cs and LayerDefinition-1_3_0.cs.

 

You can copy these 2 classes into your project, if the project deals with FeatureSource and LayerDefinition. Better yet, you would place them in a shared class library, so that you only copy them once, just as the SDK sample project "Platform.Samples.Unit" does.

 

HTH

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 9 of 9

Anonymous
Not applicable

thanx..its working now 😊

0 Likes