+ All Categories
Home > Documents > © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

Date post: 19-Dec-2015
Category:
View: 302 times
Download: 17 times
Share this document with a friend
Popular Tags:
71
© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 1 AutoCAD Map 3DPlatform API Training
Transcript
Page 1: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 1

AutoCAD Map 3DPlatform API Training

Page 2: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 2

Agenda

OverviewMap ResourcesWorking with Features

Page 3: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - "Beyond the Box” Expanding the Developers Toolbox 3

Overview

Page 4: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 4

AutoCAD Map 3D 2009 API

AutoCAD API

Ma

p O

bje

ctA

RX

AP

I

Ma

p L

ISP

/AD

SR

X A

PI

Ma

p .N

ET

AP

I

Ma

p A

ctiv

eX A

PI

FDO API

Ma

p 3

D P

latf

orm

AP

IAcDb

Entities

FDO Data Store

Features

Page 5: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 5

The Geospatial APIs

FDO

Geospatial Platform

MapGuide

Coordinate System

Resource Service

Feature Service

Geometry

Exceptions

System Types

Collections

Mapping Service

Drawing Service

Rendering Service

Tiling Service

Shared Code SharedInterface

Site Service Map 3D

Platform

API

Page 6: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 6

API Components

ExceptionsCollections

Map and Layers Geometry

Resource Service

Common

Feature Service Feature-Entity Service

Coordinate System

Page 7: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 7

Resource ServiceResources Files and configuration information

required for map and layer display Layer definition and Feature source Stored in drawings or drawing

templates and are specific to the

drawing

Resource Service Used for manipulating resources Adding resources to Map Copying resources Checking for existence of resources Getting the contents of a resource

SDFSHP

Oracle

Library://

LayerDef.

FeatureSrc.

DW

G D

ata

ba

se

Repository

Page 8: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 8

Feature Service Provides access to FDO functionality

Determine available providers and their capabilities

Verify connection property values and test connection

Provides schema information Insert, delete, update and select

features Execute SQL commands

Feature Service

FDO

Page 9: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 9

Feature-Entity Service

Enables AutoCAD Selection API support for Features Selection set management

Support for feature highlighting

New

AcMapFeatureEntityService

Page 10: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 10

Map and Layers

Provides access to map, layer groups and layers

AcMapMap represents the map shown in the Display Manager

Map layers are FDO layers

Get and set map and layer properties

MgLayerCollectionMgLayerCollectionMgLayerGroupCollectionMgLayerGroupCollection

MgMapBaseMgMapBase

AcMapMapAcMapMap

MgLayerBaseMgLayerBase

AcMapLayerAcMapLayer

MgLayerGroupMgLayerGroup

AcMapLayerGroupAcMapLayerGroup

Page 11: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 11

Geometry

Contains geometric object

types and operations to

manipulate themSupports

spatial comparisons between objects

creation of new objects based on the intersection, difference, or union of existing objects

creation of buffers around objects

MgMultiPolygonMgMultiPolygon

MgPoint MgPoint

MgLineStringMgLineString

MgPolygonMgPolygon

MgCurveStringMgCurveString

MgCurvePolygonMgCurvePolygon

MgMultiPointMgMultiPoint

MgMultiLineStringMgMultiLineString

MgMultiCurveStringMgMultiCurveString

MgMultiCurvePolygonMgMultiCurvePolygon

MgMultiGeometryMgMultiGeometry

Page 12: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 12

Coordinate Systems

MgCoordinateSystem MgCoordinateSystem

MgCoordinateSystemType MgCoordinateSystemType

MgCoordinateSystemTransform MgCoordinateSystemTransform

MgCoordinateSystemMeasure MgCoordinateSystemMeasure

MgCoordinateSystemFactory MgCoordinateSystemFactory

Provides unified access to

coordinate system information Enables coordinate system

transformations

Page 13: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 13

Utility Classes

Common The Common classes

provide a set of utility classes

MgByte MgByte

MgByteSinkMgByteSink

MgServiceMgService

MgMimeTypeMgMimeType

MgFeatureInformationMgFeatureInformation

MgByteReaderMgByteReader

MgByteSourceMgByteSource

MgColorMgColor

MgDateTimeMgDateTime

MgWarningMgWarning

Page 14: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 14

Utility Classes

MgByteSource Byte data source with a specific

content type Can be initialized from an array

of bytes in memory or a file

MgByteReader Reads data from MgByteSource

MgByteSource::GetReader()

 MgByteSink Used for writing MgByteReader

data to file Construct with MgByteReader and

call ToFIle()

MgByteSourceMgByteSource

MgByteReaderMgByteReader

MgByteSinkMgByteSink

File

byte [ ]

Other APIsOther APIs

A<{9>$

Page 15: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 15

Utility Classes

Collections Container for a set

of

objects of the same

type

MgCollection MgCollection

MgStringCollectionMgStringCollection

MgPolygonCollectionMgPolygonCollection

MgLineStringCollectionMgLineStringCollection

MgCoordinateCollectionMgCoordinateCollection

MgGeometryCollectionMgGeometryCollection

MgIntCollectionMgIntCollection

MgPointCollectionMgPointCollection

MgPropertyCollectionMgPropertyCollection

MgLinerRingCollectionMgLinerRingCollection

MgCurveRingCollectionMgCurveRingCollection

MgFeatureSchemaCollectionMgFeatureSchemaCollection

Page 16: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 16

Utility Classes

Exceptions A set of classes

representing all possible exceptions that can be generated by the application.

100+ classes

MgFileNotFoundException MgFileNotFoundException

MgGeometryExceptionMgGeometryException

MgInvalidCoordinate-

SystemException

MgInvalidCoordinate-

SystemException

MgFileIoExceptionMgFileIoException

MgFdoExceptionMgFdoException

MgOutOfMemoryExceptionMgOutOfMemoryException

MgClassNotFoundExceptionMgClassNotFoundException

MgInvalidCastExceptionMgInvalidCastException

MgResourcesExceptionMgResourcesException

MgOverflowExceptionMgOverflowException

Page 17: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 17

Getting StartedDevelopment Environment Visual Studio 2005

Assemblies Geospatial Platform Autodesk.Map.Platform.dll (Map installation folder)

AutoCAD acmgd.dll, acdbmgd.dll (Map installation folder)

FDO OSGeo.FDO.dll, OSGeo.FDO.Common.dll, OSGeo.FDO.Geometry.dll

(<Map folder>\FDO\bin)

Page 18: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 18

Getting Started

FDO

Geo

spat

ial P

latf

orm

AP

I M

ap P

latf

orm

AP

I

Namespaces Autodesk.Gis.Map.Platform Autodesk.Gis.Map.Platform.Interop OSGeo.MapGuide OSGeo.FDO* OSGeo.FDO.Common*

Page 19: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 19

Getting StartedDEMO – Basic information about a map Project language (C# or VB) and type (Class library) Assembly references Map 3D - Autodesk.Map.Platform.dll AutoCAD – acmgd.dll

Set the Copy Local properties of the assembly to False

Command Create command function with CommandMethod attribute Access map properties

Page 20: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - "Beyond the Box” Expanding the Developers Toolbox 20

Map Resources

Page 21: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 21

Map Resources Files and configuration information

required for map and layer display Stored in XML format in the resource

repository Has a unique path in the repository. e.g.

Library://Data/Raster/Redding.LayerDefinition, Library://Data/SDF/Zoning.FeatureSource

Resource types Layer definition (LayerDefinition) Feature source (FeatureSource)

Resource service Methods of AcMapResourceService are used for

creating resources

MgResourceServiceMgResourceService

AcMapResourceServiceAcMapResourceService

Page 22: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 22

Map ResourcesLayerDefinition and FeatureSource Resource Identifier of the FeatureSource is used in LayerDefinition

.sdf

Map Layers

Data Source

FeatureSource

Lib

rary

://S

DF

_1.F

eatu

reS

ou

rce

Lib

rary

://S

DF

_1.L

ayer

Def

init

ion

LayerDefinition

Page 23: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 23

Map ResourcesCreating a resource service

Resource Identifier Defines the location of a resource in the repository Encapsulated in MgResourceIdentifier Resource pointed to does not need to exist yet

// Create a resource Id for a layer definition resourceMgResourceIdentifier LayerDefResId = new MgResourceIdentifier("Library://Data/Raster/Redding.LayerDefinition");

// Create a resource Id for a feature source resourceMgResourceIdentifier FtrSrcResId = new MgResourceIdentifier("Library://Data/Raster/Redding.FeatureSource");

// Create a resource Id for a layer definition resourceMgResourceIdentifier LayerDefResId = new MgResourceIdentifier("Library://Data/Raster/Redding.LayerDefinition");

// Create a resource Id for a feature source resourceMgResourceIdentifier FtrSrcResId = new MgResourceIdentifier("Library://Data/Raster/Redding.FeatureSource");

// Get an MgService object from AcMapServiceFactory and cast it to AcMapResourceServiceAcMapResourceService resServ = (AcMapResourceService)AcMapServiceFactory.GetService(MgServiceType.ResourceService);

// Get an MgService object from AcMapServiceFactory and cast it to AcMapResourceServiceAcMapResourceService resServ = (AcMapResourceService)AcMapServiceFactory.GetService(MgServiceType.ResourceService);

Page 24: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 24

Map ResourcesGetting Resource Content Get the XML content of a LayerDefinition or FeatureSource

using MgResourceService::GetResourceContent

//Get the content of a FeatureSourceMgResourceIdentifier id = new MgResourceIdentifier("Library://Data/Raster/Redding.FeatureSource");MgResourceService resServ = (AcMapResourceService)AcMapServiceFactory.GetService(MgServiceType.ResourceService);bool resourceExists = resServ.ResourceExists(id);MgByteReader byteRdr = null; if (resourceExists ) { byteRdr = resServ.GetResourceContent(id); MgByteSink byteSink = new MgByteSink(byteRdr); byteSink.ToFile(@"c:\FeatureResource.Xml"); }

//Get the content of a FeatureSourceMgResourceIdentifier id = new MgResourceIdentifier("Library://Data/Raster/Redding.FeatureSource");MgResourceService resServ = (AcMapResourceService)AcMapServiceFactory.GetService(MgServiceType.ResourceService);bool resourceExists = resServ.ResourceExists(id);MgByteReader byteRdr = null; if (resourceExists ) { byteRdr = resServ.GetResourceContent(id); MgByteSink byteSink = new MgByteSink(byteRdr); byteSink.ToFile(@"c:\FeatureResource.Xml"); }

Page 25: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 25

Map ResourcesFeature Source Describes the information

required to connect to the data source

See FeatureSource-1.0.0.xsd in “<Map 3D 2009 SDK Folder>\Schema”

Referenced via “ResourceId” element in a LayerDefinition XML

Connect to an FDO provider by creating a feature source xml file and adding it to the repository

Page 26: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 26

Map ResourcesFeature Source Elements “Provider” specifies the name of the FDO provider used “Parameter” specifies a collection of name/value pairs for

connecting to the data source <FeatureSource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FeatureSource-1.0.0.xsd" version="1.0.0">

<Provider>OSGeo.SDF.3.3</Provider>

<Parameter>

<Name>ReadOnly</Name>

<Value>false</Value>

</Parameter>

<Parameter>

<Name>File</Name>

<Value>C:\Data\SDF\Signals.sdf</Value>

</Parameter>

<ConfigurationDocument></ConfigurationDocument>

<LongTransaction></LongTransaction>

</FeatureSource>

Page 27: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 27

Map ResourcesCreating a feature source in the repository Step 1: Generate feature source XML data

//XML Data from existing FeatureSource XML file// Load XML into memory and modifyXmlDocument doc = new XmlDocument();doc.Load(C:\XML\SampleFeatureSource.xml")// Make modificationsXmlNode providerNode = doc.GetElementsByTagName(“Provider");providerNode.InnerText = “OSGeo.SHP.3.3”;

//Save changes into a memory streamMemoryStream xmlStream = new MemoryStream();doc.Save(xmlStream);

//Get Feature source as a byte array byte [] ftrSrc = xmlStream.ToArray();

Encoding utf8 = Encoding.UTF8;String StrFtrSrc = new String(utf8.GetChars(ftrSrc));ftrSrc = new byte[StrFtrSrc .Length-1];

//XML Data from existing FeatureSource XML file// Load XML into memory and modifyXmlDocument doc = new XmlDocument();doc.Load(C:\XML\SampleFeatureSource.xml")// Make modificationsXmlNode providerNode = doc.GetElementsByTagName(“Provider");providerNode.InnerText = “OSGeo.SHP.3.3”;

//Save changes into a memory streamMemoryStream xmlStream = new MemoryStream();doc.Save(xmlStream);

//Get Feature source as a byte array byte [] ftrSrc = xmlStream.ToArray();

Encoding utf8 = Encoding.UTF8;String StrFtrSrc = new String(utf8.GetChars(ftrSrc));ftrSrc = new byte[StrFtrSrc .Length-1];

Page 28: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 28

Map ResourcesCreating a feature source in the repository+ Step 2: Construct MgByteSource object from XML data Step 3: Extract data from MgByteSource object and add as

(feature source) resource to the repository

// Construct byteSource object from dataMgByteSource byteSource = new MgByteSource(ftrSrc, ftrSrc.Length);byteSource.SetMimeType(MgMimeType.Xml);

// Add to repositoryMgResourceIdentifier resId = new MgResourceIdentifier(“Library://Data/Raster/Redding.FeatureSource“);AcMapResourceService rs = AcMapServiceFactory.GetService(MgServiceType.ResourceService) as AcMapResourceService;rs.SetResource(resId, byteSource .GetReader(), null);

// Construct byteSource object from dataMgByteSource byteSource = new MgByteSource(ftrSrc, ftrSrc.Length);byteSource.SetMimeType(MgMimeType.Xml);

// Add to repositoryMgResourceIdentifier resId = new MgResourceIdentifier(“Library://Data/Raster/Redding.FeatureSource“);AcMapResourceService rs = AcMapServiceFactory.GetService(MgServiceType.ResourceService) as AcMapResourceService;rs.SetResource(resId, byteSource .GetReader(), null);

Page 29: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 29

Map Resources Layer Definition Specification of the data source and stylization information for a

layer See LayerDefinition-1.2.0.xsd in “<Map 3D 2009 SDK Folder>\

Schema” Required for creating a layer

Page 30: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 30

Map ResourcesLayer Definition Elements “ResourceId” defines the link to the data source through the

FeatureSource “VectorScaleRange”/”GridScaleRange” defines the

stylization

to be applied to the features for a given scale range “Geometry” specifies the geometry property that should be

used to get the feature geometries “FeatureName” specifies a feature class or named

extension

Page 31: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 31

Map ResourcesLayer Definition

Page 32: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 32

Map ResourcesCreating a layer definition in the repository Step 1: Generate layer definition XML data

//XML Data from existing LayerDefinition XML file// Load XML into memory and modifyXmlDocument doc = new XmlDocument();doc.Load(C:\XML\SampleLayerDefinition.xml")// Make modificationsXmlNode ftrSrcNode = doc.GetElementsByTagName("ResourceId").Item(0);ftrSrcNode.InnerText = "Library://Data/Shp/Roads.FeatureSource”;

//Save changes into a memory streamMemoryStream xmlStream = new MemoryStream();doc.Save(xmlStream);

//Get Feature source as a byte array byte [] layerDef = xmlStream.ToArray();

Encoding utf8 = Encoding.UTF8;String strLayerDef = new String(utf8.GetChars(layerDef ));bytes = new byte[strLayerDef.Length-1];

//XML Data from existing LayerDefinition XML file// Load XML into memory and modifyXmlDocument doc = new XmlDocument();doc.Load(C:\XML\SampleLayerDefinition.xml")// Make modificationsXmlNode ftrSrcNode = doc.GetElementsByTagName("ResourceId").Item(0);ftrSrcNode.InnerText = "Library://Data/Shp/Roads.FeatureSource”;

//Save changes into a memory streamMemoryStream xmlStream = new MemoryStream();doc.Save(xmlStream);

//Get Feature source as a byte array byte [] layerDef = xmlStream.ToArray();

Encoding utf8 = Encoding.UTF8;String strLayerDef = new String(utf8.GetChars(layerDef ));bytes = new byte[strLayerDef.Length-1];

Page 33: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 33

Map ResourcesCreating a layer definition in the repository Step 2: Construct MgByteSource object from XML data Step 3: Extract data from MgByteSource object and add as

layer definition resource to the repository

// Construct byteSource object from dataMgByteSource byteSource = new MgByteSource(bytes , bytes.Length);byteSource.SetMimeType(MgMimeType.Xml);

// Add to repositoryMgResourceIdentifier resId = new MgResourceIdentifier(“Library://Data/Raster/Redding.LayerDefinition“);AcMapResourceService rs = AcMapServiceFactory.GetService(MgServiceType.ResourceService) as AcMapResourceService;rs.SetResource(resId, byteSource .GetReader(), null);

// Construct byteSource object from dataMgByteSource byteSource = new MgByteSource(bytes , bytes.Length);byteSource.SetMimeType(MgMimeType.Xml);

// Add to repositoryMgResourceIdentifier resId = new MgResourceIdentifier(“Library://Data/Raster/Redding.LayerDefinition“);AcMapResourceService rs = AcMapServiceFactory.GetService(MgServiceType.ResourceService) as AcMapResourceService;rs.SetResource(resId, byteSource .GetReader(), null);

Page 34: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 34

Resource Service Events Occur when resource-related actions, such as resource

addition, modification or removal occur

Event functions are members of AcMapResourceService

Page 35: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 35

ResourceService Events

//Handling the ResourceAdded event //declare delegate objectprivate static ResourceAddedHandler g_eventHandler = null;public bool RegisterEvent(){ AcMapResourceService rs = AcMapServiceFactory.GetService(MgServiceType.ResourceService) as AcMapResourceService; //Create an instance of the delegate g_eventHandler = new ResourceAddedHandler(this.MyEventHandlerFunction); //Associate delegate with the event rs.ResourceAdded += g_eventHandler; }

//Implement handler functionprivate void MyEventHandlerFunction (object sender, AcMapResourceEventArgs args){ MgResourceIdentifier resId = args.GetResourceIdentifier(); MessageBox.Show(resId.ToString() + “ added”);}

//Handling the ResourceAdded event //declare delegate objectprivate static ResourceAddedHandler g_eventHandler = null;public bool RegisterEvent(){ AcMapResourceService rs = AcMapServiceFactory.GetService(MgServiceType.ResourceService) as AcMapResourceService; //Create an instance of the delegate g_eventHandler = new ResourceAddedHandler(this.MyEventHandlerFunction); //Associate delegate with the event rs.ResourceAdded += g_eventHandler; }

//Implement handler functionprivate void MyEventHandlerFunction (object sender, AcMapResourceEventArgs args){ MgResourceIdentifier resId = args.GetResourceIdentifier(); MessageBox.Show(resId.ToString() + “ added”);}

Page 36: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 36

Map Layers A map (AcMapMap) is composed

of one or more layers (AcMapLayer)

Get the resource identifier of a layer’s definition in the repository using GetLayerDefinition()

MgLayerCollectionMgLayerCollection

MgMapBaseMgMapBase

AcMapMapAcMapMap

MgLayerBaseMgLayerBase

AcMapLayerAcMapLayer

//Getting the map object AcMapMap map = AcMapMap.GetCurrentMap();

//Getting a layer in the map//MgLayerCollection::GetItem() returns MgLayerBase AcMapLayer layer = (AcMapLayer) map.GetLayers(). GetItem(0); //Getting the layer definition contentMgResourceIdentifier layerResId = layer.GetLayerDefinition();AcMapResourceService rs = (AcMapResourceService)AcMapServiceFactory.GetService(MgServiceType.ResourceService);MgByteReader byteRdr = rs.GetResourceContent(layerResId);

//Getting the map object AcMapMap map = AcMapMap.GetCurrentMap();

//Getting a layer in the map//MgLayerCollection::GetItem() returns MgLayerBase AcMapLayer layer = (AcMapLayer) map.GetLayers(). GetItem(0); //Getting the layer definition contentMgResourceIdentifier layerResId = layer.GetLayerDefinition();AcMapResourceService rs = (AcMapResourceService)AcMapServiceFactory.GetService(MgServiceType.ResourceService);MgByteReader byteRdr = rs.GetResourceContent(layerResId);

Page 37: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 37

Adding Layers to a Map Add .LAYER file using AcMapMap::LoadLayer() Creating and adding a new layer

Add layer definition to repository Create new layer using resource ID of layer definition Add new layer to map layer collection

//Addding layer definition to repository AcMapResourceService rs = (AcMapResourceService)AcMapServiceFactory.GetService(MgServiceType.ResourceServiceMgByteSource layer_byteSource //Assume byte source contains layer definition data MgResourceIdentifier layerResId = new (“Library://Data/SDF/Newlayer.LayerDefinition”);Rs.SetResource(layerResId, layer_byteSource.GetReader(), null);

//Creating a new layerAcMapLayer layer = AcMapLayer.Create(layerResId,rs); //NEW!Layer.SetName(“Roads”);

//Addding new layer to map layer collectionMgLayerCollection layers = (AcMapLayer) AcMapMap.GetCurrentMap().GetLayers();Layers.Add(layer);

//Addding layer definition to repository AcMapResourceService rs = (AcMapResourceService)AcMapServiceFactory.GetService(MgServiceType.ResourceServiceMgByteSource layer_byteSource //Assume byte source contains layer definition data MgResourceIdentifier layerResId = new (“Library://Data/SDF/Newlayer.LayerDefinition”);Rs.SetResource(layerResId, layer_byteSource.GetReader(), null);

//Creating a new layerAcMapLayer layer = AcMapLayer.Create(layerResId,rs); //NEW!Layer.SetName(“Roads”);

//Addding new layer to map layer collectionMgLayerCollection layers = (AcMapLayer) AcMapMap.GetCurrentMap().GetLayers();Layers.Add(layer);

Page 38: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 38

Map Events Triggered when layers or features are added to or

removed from the map

Event functions are members of AcMapMap

Page 39: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 39

Map Resources

DEMO – Creating Resources Connect to feature sources Create layers

Page 40: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - "Beyond the Box” Expanding the Developers Toolbox 40

Working with Features

Page 41: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 41

Feature Service

Uses Storage and retrieval of features Information about FDO Providers and their capabilities Information about schemas and feature classes

Page 42: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 42

Creating the Feature Service

Feature service is created from AcMapServiceFactory object using the GetService method

// Get the feature service AcMapFeatureService featureService = AcMapServiceFactory.GetService(ServiceType.FeatureService) as AcMapFeatureService;

// Get the feature service AcMapFeatureService featureService = AcMapServiceFactory.GetService(ServiceType.FeatureService) as AcMapFeatureService;

MgFeatureServiceMgFeatureService

AcMapFeatureServiceAcMapFeatureService

Page 43: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 43

FDO Registry Get FDO registry and list the providers

with the GetFeatureProviders method

// Get the registered feature providersMgByteReader reader = featureService.GetFeatureProviders(); String providers = reader.ToString();

// Get the registered feature providersMgByteReader reader = featureService.GetFeatureProviders(); String providers = reader.ToString();

Page 44: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 44

FDO Provider Capabilities

Different FDO providers have different capabilities.

For example SHP and SDF don’t support

topology. Oracle and SQL Server support

database transaction. Get a provider’s capability

programmatically using the GetCapabilities method

// Get the capabilities of a provider MgByteReader reader = featureService.GetCapabilities(fullProviderName);

// Get the capabilities of a provider MgByteReader reader = featureService.GetCapabilities(fullProviderName);

FDO Provider Capabilities

Page 45: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 45

Feature Schema (MgFeatureSchema)

Defines the structure of data in a feature source Associated with a feature source

Contains one or more feature classes

// Get the XML representation of a feature schema MgResourceIdentifier id = new MgResourceIdentifier("Library://Data/Raster/Redding.FeatureSource");String schema = featureService.DescribeSchemaAsXml(id, “ReddingSchema");

// Get the XML representation of a feature schema MgResourceIdentifier id = new MgResourceIdentifier("Library://Data/Raster/Redding.FeatureSource");String schema = featureService.DescribeSchemaAsXml(id, “ReddingSchema");

Page 46: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 46

Feature Schema

Getting existing schemas

Creating a new schema – use FDO API

// Get the names of all schemas in a feature source MgResourceIdentifier id = new MgResourceIdentifier("Library://Data/Raster/Redding.FeatureSource");MgStringCollection schemaNames = featureService.GetSchemas(id);MgFeatureSchema schema = null;

// Get a particular schemaforeach( String schemaName in schemaNames){ if(schemaName.ToLower() == “reddingschema") { schema = featureService.DescribeSchema(id, schemaName).GetItem(0); break; }}

// Get the names of all schemas in a feature source MgResourceIdentifier id = new MgResourceIdentifier("Library://Data/Raster/Redding.FeatureSource");MgStringCollection schemaNames = featureService.GetSchemas(id);MgFeatureSchema schema = null;

// Get a particular schemaforeach( String schemaName in schemaNames){ if(schemaName.ToLower() == “reddingschema") { schema = featureService.DescribeSchema(id, schemaName).GetItem(0); break; }}

Page 47: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 47

Feature Class (MgClassDefinition)

Database-table-like structure Feature class contains

properties corresponding to table columns.

Property types: Geometry Data Raster Object

Identity properties are used to uniquely identify a feature in a feature class.

ID

GE

OM

OW

NE

R

VA

LU

E

SIZ

E

Geo

metry

Iden

tity

Data

Page 48: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 48

MgClassDefinition

Sets class properties Used to describe or create

feature classes Important methods

SetDefaultGeometryPropertyName() GetProperties()

Returns MgPropertyDefinitionCollection

GetIdentityProperties() Returns

MgPropertyDefinitionCollection

Page 49: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 49

MgPropertyDefinition

MgPropertyDefinition The details of a feature class property Has 4 subclasses or types

MgDataPropertyDefinition MgGeometricPropertyDefinition MgRasterPropertyDefinition MgObjectPropertyDefinition

Page 50: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 50

MgGeometricPropertyDefinition

Defines a geometric property Important methods

SetHasElevation() SetReadOnly() SetSpatialContextAssociation SetGeometryTypes()

Types of geometric properties MgFeatureGeometricType

Point – 1 Curve – 2 Surface – 4 Solid – 8

Page 51: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 51

MgDataPropertyDefinition Defines a data property Important methods

SetAutoGeneration() SetDefaultValue() SetLength() SetNullable() SetPrecision() SetReadOnly() SetScale()

Types of data properties MgPropertyType

Double (5), Int32 (7),

String (9)...

Page 52: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 52

Feature Class(MgClassDefinition) Examining a schema

MgResourceIdentifier id = new MgResourceIdentifier("Library://Data/Raster/Redding.FeatureSource");MgClassDefinition classDef; MgStringCollection schemaNames = featureService.GetSchemas(id);

// Get a schema and look at a class definitionforeach( String schemaName in schemaNames){ if(schemaName.ToLower() == “reddingschema") { classDef = featureService.GetClassDefinition(id,schemaName,”className”); // MgPropertyDefinitionCollection allPropDefs = classDef.GetProperties(); foreach(MgPropertyDefinition propDef in allPropDefs) { if(propDef.GetPropertyType() == MgFeaturePropertyType.DataProperty) { MgDataPropertyDefinition somePropDef = (MgDataPropertyDefinition) propDef ;

int dataType = somePropDef.GetDataType() ; } else if(propDef.GetPropertyType() == MgFeaturePropertyType.GeometricProperty) { //We examine the type of geometry stored in the class MgGeometricPropertyDefinition geomPropDef = (MgGeometricPropertyDefinition) propDef ; int geomTypes = geomPropDef.GetGeometryTypes(); //2=curve; 4=surface, etc. } } break; }}

MgResourceIdentifier id = new MgResourceIdentifier("Library://Data/Raster/Redding.FeatureSource");MgClassDefinition classDef; MgStringCollection schemaNames = featureService.GetSchemas(id);

// Get a schema and look at a class definitionforeach( String schemaName in schemaNames){ if(schemaName.ToLower() == “reddingschema") { classDef = featureService.GetClassDefinition(id,schemaName,”className”); // MgPropertyDefinitionCollection allPropDefs = classDef.GetProperties(); foreach(MgPropertyDefinition propDef in allPropDefs) { if(propDef.GetPropertyType() == MgFeaturePropertyType.DataProperty) { MgDataPropertyDefinition somePropDef = (MgDataPropertyDefinition) propDef ;

int dataType = somePropDef.GetDataType() ; } else if(propDef.GetPropertyType() == MgFeaturePropertyType.GeometricProperty) { //We examine the type of geometry stored in the class MgGeometricPropertyDefinition geomPropDef = (MgGeometricPropertyDefinition) propDef ; int geomTypes = geomPropDef.GetGeometryTypes(); //2=curve; 4=surface, etc. } } break; }}

Page 53: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 53

Feature PropertiesMgPropertyCollection Class Holds the property values used to

create or update features Must contain the values for the non-

nullable properties For example, to update a feature

class with schema like the one shown, the MgPropertyCollection object must contain these properties ID – MgInt32Property GEOM - MgGeometryProperty OWNER - MgStringProperty

ID

GEOM

OWNER

VALUE

SIZE

Properties Nullable

Page 54: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 54

Feature Geometry Representation Geometry data formats

AGF text format (extension of OGC WKT), represents geometry as a character string “LINESTRING XY (0 0 , 1 -1)”, “POLYGON XY ((1 -3, 4 -3, 4 -6, 1 -6, 1 -3), (2 -4, 3 -4, 3 -5, 2 -5, 2 -4))”

Binary AGF format - MgByteReader Internal representation, using MgGeometry or subclasses

API for getting feature coordinates

Translation MgAgfReaderWriter is used to translate between binary AGF and

MgGeometry MgWktReaderWriter is used to translate between AGF Text and

MgGeometry

Page 55: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 55

Geometry Format Conversion Use MgAgfReaderWriter to translate between binary AGF and

MgGeometry, and MgWktReaderWriter to translate between AGF Text and MgGeometry

// Binary AGF -> MgGeometryMgAgfReaderWriter agfRW = new MgAgfReaderWriter();// assume byteRdr, an MgByteReader object, contains a (binary) geometryMgGeometry geom = agfRW.Read(byteRdr);

// MgGeometry -> Binary AGFMgAgfReaderWriter agfRW = new MgAgfReaderWriter();// assume geom, an MgGeometry is already definedMgByteReader byteRdr= agfRW.Write(geom);

// AGF Text -> MgGeometryMgWktReaderWriter wktRW = new MgWktReaderWriter();String wktStr = “POINT XY (1 -1)”;MgGeometry geom = wktRW.Read(wktStr);

// MgGeometry -> AGF TextMgWktReaderWriter wktRW = new MgWktReaderWriter();// assume geom, an MgGeometry is already definedString wktStr = wktRW.Write(geom);

// Binary AGF -> MgGeometryMgAgfReaderWriter agfRW = new MgAgfReaderWriter();// assume byteRdr, an MgByteReader object, contains a (binary) geometryMgGeometry geom = agfRW.Read(byteRdr);

// MgGeometry -> Binary AGFMgAgfReaderWriter agfRW = new MgAgfReaderWriter();// assume geom, an MgGeometry is already definedMgByteReader byteRdr= agfRW.Write(geom);

// AGF Text -> MgGeometryMgWktReaderWriter wktRW = new MgWktReaderWriter();String wktStr = “POINT XY (1 -1)”;MgGeometry geom = wktRW.Read(wktStr);

// MgGeometry -> AGF TextMgWktReaderWriter wktRW = new MgWktReaderWriter();// assume geom, an MgGeometry is already definedString wktStr = wktRW.Write(geom);

Page 56: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 56

Retrieving Features MgFeatureService and AcMapLayer have methods for retrieving

features – use AcMapLayer methods AcMapLayer::SelectFeatures() retrieves features based on

conditions specified through MgFeatureQueryOptions MgFeatureQueryOptions may also contain no conditions

AcMapLayer::GetFeatures() retrieves features given their Ids AcMapLayer::GetLockedFeatures() retrieves locked (i.e.

checked out) features Methods return an MgFeatureReader object

MgFeatureReader implements a forward-only, read-only iterator for reading features

Use ReadNext() to advance iterator – call at least once Use the GetXXX functions to get property values, given the name,

e.g. GetInt32(“ID”) – returns the ID of the feature the iterator is currently pointing to

Use feature property to interact with feature, e.g. highlight it Always close MgFeatureReader object after use

Page 57: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 57

Retrieving Features+

//Get all features on “Roads” layer – no conditions (filtering)MgLayerCollection layers = AcMapMap.GetCurrentMap().GetLayers();//Get layerAcMapLayer rdLayer = (AcMapLayer)layers.GetItem("Roads");//Define (empty) query objectMgFeatureQueryOptions query = new MgFeatureQueryOptions()//Retrieve featuresMgFeatureReader featureReader = rdLayer.SelectFeatures(query);//Get feature propertieswhile (featureReader.ReadNext()) { int streetID = featureReader.GetInt32("ID"); string streetName = featureReader.GetString(“ST_NAME”); double streetLength = featureReader.GetDouble(“LENGTH”);}featureReader.Close();

//Get all features on “Roads” layer – no conditions (filtering)MgLayerCollection layers = AcMapMap.GetCurrentMap().GetLayers();//Get layerAcMapLayer rdLayer = (AcMapLayer)layers.GetItem("Roads");//Define (empty) query objectMgFeatureQueryOptions query = new MgFeatureQueryOptions()//Retrieve featuresMgFeatureReader featureReader = rdLayer.SelectFeatures(query);//Get feature propertieswhile (featureReader.ReadNext()) { int streetID = featureReader.GetInt32("ID"); string streetName = featureReader.GetString(“ST_NAME”); double streetLength = featureReader.GetDouble(“LENGTH”);}featureReader.Close();

Page 58: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 58

Filters

Basic Filter Used to perform queries on

feature attributes Uses SQL-type conditions

Comparison>, <, <>, >=, <=

Like In

May contain expressions functions Avg Sum Count Min, Max …

YEAR > 1990 and Year < 2000NAME like “Richmond%”RVALUE in (500000, 1000000)DATE > ‘1995-3-15’ADDRESS NULL

YEAR > 1990 and Year < 2000NAME like “Richmond%”RVALUE in (500000, 1000000)DATE > ‘1995-3-15’ADDRESS NULL

Filter String Examples

Page 59: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 59

Filters+

Spatial Filter Query based on the relationship of two geometries Two ways to set spatial filters on MgFeatureQueryOptions

SetFilter() – basic filter format, specifying geometry using GEOMFROMTEXT()

SetSpatialFilter() – requires 3 parameters: a name which identifies the geometry property of a feature, a geometry object, and a spatial operation identifier

Page 60: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 60

Spatial Filter Operations Contains Crosses Disjoint Equals Intersects Overlaps Touches Within Inside

Note: Supported operation is determined by provider’s capabilities

Crosses

Intersects

Touches

Within

Disjoint

Overlaps

Spatial Relationship

Page 61: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 61

Filter-based Selection// Define a query option and specify it’s criteria using a basic filterMgFeatureQueryOptions query = new MgFeatureQueryOptions();query.SetFilter("Year >= 1990");

// Get the features MgFeatureReader featureReader = layer.SelectFeatures(query);

// SPATIAL FILTER – using SetFilter()//WKT representation of a geometrystring areaWkt = "'POLYGON XY((1874913.0097 430949.2330, 1874913.0097 463071.9745,1898944.6847 ";areaWkt += "463071.9745,1898944.6847 430949.2330, 1874913.0097 430949.2330))'"; //spatial relationship inside a basic filterMgFeatureQueryOptions query = new MgFeatureQueryOptions();query.SetFilter("Geometry inside GEOMFROMTEXT(" + areaWkt + ")");// Get the features MgFeatureReader featureReader = layer.SelectFeatures(query);

// SPATIAL FILTER – using SetSpatialFilterMgGeometry aGeometryObject;query.SetSpatialFilter("SHPGEOM", aGeometryObject, MgFeatureSpatialOperations.Inside);MgFeatureReader featureReader = layer.SelectFeatures(query);

// Define a query option and specify it’s criteria using a basic filterMgFeatureQueryOptions query = new MgFeatureQueryOptions();query.SetFilter("Year >= 1990");

// Get the features MgFeatureReader featureReader = layer.SelectFeatures(query);

// SPATIAL FILTER – using SetFilter()//WKT representation of a geometrystring areaWkt = "'POLYGON XY((1874913.0097 430949.2330, 1874913.0097 463071.9745,1898944.6847 ";areaWkt += "463071.9745,1898944.6847 430949.2330, 1874913.0097 430949.2330))'"; //spatial relationship inside a basic filterMgFeatureQueryOptions query = new MgFeatureQueryOptions();query.SetFilter("Geometry inside GEOMFROMTEXT(" + areaWkt + ")");// Get the features MgFeatureReader featureReader = layer.SelectFeatures(query);

// SPATIAL FILTER – using SetSpatialFilterMgGeometry aGeometryObject;query.SetSpatialFilter("SHPGEOM", aGeometryObject, MgFeatureSpatialOperations.Inside);MgFeatureReader featureReader = layer.SelectFeatures(query);

Page 62: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 62

Inserting Features Inserting features is performed using MgInsertFeatures Steps

Create an MgPropertyCollection object, and add the property values of the new feature

Create an MgInsertFeatures object using the MgPropertyCollection object and the name of the feature class, which is to be inserted

Commit insertion

MgPropertyCollection props = new MgPropertyCollection();MgAgfReaderWriter agfWriter = new MgAgfReaderWriter();MgGeometry geom; //assuming this is already defined

//Convert MgGeometry to MgByteReaderMgByteReader byteRdr = agfWriter.Write(geom);

props.Add(new MgGeometryProperty("GEOM",byteRdr));props.Add(new MgStringProperty ("LOTDIM", "540X400"));props.Add(new MgInt32Property("SQFT", 6600));props.Add(new MgStringProperty("ZONE", "RES" ));

MgInsertFeatures insertFeatures = new MgInserrtFeatues ("Parcels", properties);

MgPropertyCollection props = new MgPropertyCollection();MgAgfReaderWriter agfWriter = new MgAgfReaderWriter();MgGeometry geom; //assuming this is already defined

//Convert MgGeometry to MgByteReaderMgByteReader byteRdr = agfWriter.Write(geom);

props.Add(new MgGeometryProperty("GEOM",byteRdr));props.Add(new MgStringProperty ("LOTDIM", "540X400"));props.Add(new MgInt32Property("SQFT", 6600));props.Add(new MgStringProperty("ZONE", "RES" ));

MgInsertFeatures insertFeatures = new MgInserrtFeatues ("Parcels", properties);

Page 63: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 63

Updating Features Updating features is performed using MgUpdateFeatures Steps

Create an MgPropertyCollection object, which holds the new

property values for the features to be updated. Create MgUpdateFeatures using the name of the feature class on which

the updating will be performed, the MgPropertyCollection object and a query string identifying the features to be updated

Commit update

MgPropertyCollection props = new MgPropertyCollection();

props.Add(new MgStringProperty("LOTDIM", "540X400"));props.Add(new MgInt32Property("SQFT", 6600));props.Add(new MgStringProperty("ZONE", "RES" ));MgUpdateFeatures updateFeatures = new MgUpdateFeatures ("Parcels", properties, "OWNER LIKE 'JOHN%'");

MgPropertyCollection props = new MgPropertyCollection();

props.Add(new MgStringProperty("LOTDIM", "540X400"));props.Add(new MgInt32Property("SQFT", 6600));props.Add(new MgStringProperty("ZONE", "RES" ));MgUpdateFeatures updateFeatures = new MgUpdateFeatures ("Parcels", properties, "OWNER LIKE 'JOHN%'");

Page 64: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 64

Deleting Features

Deleting features is performed using MgDeleteFeatures Create MgDeleteFeatures using the name of the feature class on

which the deletion will be carried out and a query string identifying the features to delete

Commit deletion

MgDeleteFeatures deleteFeatures = new MgDeleteFeatures ("Parcels", "ID=2354");MgDeleteFeatures deleteFeatures = new MgDeleteFeatures ("Parcels", "ID=2354");

MgDeleteFeatures deleteFeatures = new MgDeleteFeatures ("Parcels", "GEOM INTERSECTS GEOMFROMTEXT ('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))')");

MgDeleteFeatures deleteFeatures = new MgDeleteFeatures ("Parcels", "GEOM INTERSECTS GEOMFROMTEXT ('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))')");

Page 65: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 65

Committing Feature Edits

Edits of deleting, updating, and inserting are committed to the feature class by using an MgFeatureCommandCollection object MgDeleteFeatures, MgInsertFeatures and MgUpdateFeatures are

all types of MgFeatureCommand objects added to MgFeatureCommandCollection

Feature commands are executed in the order they are added to the MgFeatureCommandCollection

Command execution is initiated using AcMapLayer::UpdateFeatures()

MgFeatureCommandCollection commands = new MgFeatureCommandCollection();commands.Add(deleteFeatures);//Assuming we are executing further commandscommands.Add(updateFeatures);commands.Add(insertFeatures);//Execute commandsMgLayerCollection layers = AcMapMap.GetCurrentMap().GetLayers();AcMapLayer rdLayer = (AcMapLayer)layers.GetItem("Roads");rdLayer.UpdateFeatures(commands);

MgFeatureCommandCollection commands = new MgFeatureCommandCollection();commands.Add(deleteFeatures);//Assuming we are executing further commandscommands.Add(updateFeatures);commands.Add(insertFeatures);//Execute commandsMgLayerCollection layers = AcMapMap.GetCurrentMap().GetLayers();AcMapLayer rdLayer = (AcMapLayer)layers.GetItem("Roads");rdLayer.UpdateFeatures(commands);

Page 66: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 66

Feature Selection Sets Use AutoCAD GetSelection() to select features into

an AutoCAD selection set Use AcMapFeatureEntityService::GetSelection() to convert

AutoCAD election set to Map selection set (MgSelectionBase)

using Autodesk.Gis.Map.Platform.Interop;

Autodesk.AutoCAD.EditorInput.SelectionSet acadSel = null;

Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

//Select features in the map

selRes = ed.GetSelection();

if (selRes.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK) {

ed.WriteMessage("\nNo features selected");

return;

}

//Get the AutoCAD selection set

acadSel = selRes.Value;

//Convert AutoCAD selection set to Map (Platform) selection set

MgSelectionBase _selectionSet = AcMapFeatureEntityService.GetSelection(acadSel);

using Autodesk.Gis.Map.Platform.Interop;

Autodesk.AutoCAD.EditorInput.SelectionSet acadSel = null;

Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

//Select features in the map

selRes = ed.GetSelection();

if (selRes.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK) {

ed.WriteMessage("\nNo features selected");

return;

}

//Get the AutoCAD selection set

acadSel = selRes.Value;

//Convert AutoCAD selection set to Map (Platform) selection set

MgSelectionBase _selectionSet = AcMapFeatureEntityService.GetSelection(acadSel);

Page 67: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 67

Feature Selection Sets+Selecting features programmatically Add features Map selection set (MgSelectionBase) Use AcMapFeatureEntityService::HighlightFeatures() to select

on screen

AcMapMap map = AcMapMap.GetCurrentMap();MgLayerCollection layers = map.GetLayers(); AcMapLayer rdLayer = (AcMapLayer)layers.GetItem("Roads");

//Create a selection setMgSelectionBase ss = new MgSelectionBase(map);

//Add 2 features (ID = 4736,4709) to selection setss.AddFeatureIdInt32(rdLayer, rdLayer.FeatureClassName, 4736);ss.AddFeatureIdInt32(rdLayer, rdLayer.FeatureClassName, 4709);

//Highlight featuresAcMapFeatureEntityService.HighlightFeatures(ss);

AcMapMap map = AcMapMap.GetCurrentMap();MgLayerCollection layers = map.GetLayers(); AcMapLayer rdLayer = (AcMapLayer)layers.GetItem("Roads");

//Create a selection setMgSelectionBase ss = new MgSelectionBase(map);

//Add 2 features (ID = 4736,4709) to selection setss.AddFeatureIdInt32(rdLayer, rdLayer.FeatureClassName, 4736);ss.AddFeatureIdInt32(rdLayer, rdLayer.FeatureClassName, 4709);

//Highlight featuresAcMapFeatureEntityService.HighlightFeatures(ss);

Page 68: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 68

Feature Service Events Occur when feature-related actions, such as deletion,

insertion or update are initiated, concluded or cancelled

Event functions are members of AcMapFeatureService

Page 69: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 69

Feature Service Events+

//Handling the FeatureInserted event //declare delegate objectprivate static FeatureInsertedHandler g_eventHandler = null;public bool RegisterEvent(){ AcMapFeatureService fs = AcMapServiceFactory.GetService(MgServiceType.FeatureService) as AcMapFeatureService; //Create an instance of the delegate g_eventHandler = new FeatureInsertedHandler(this.MyEventHandlerFunction); //Associate delegate with the event fs.FeatureInserted += g_eventHandler; }

//Implement handler functionprivate void MyEventHandlerFunction (object sender, AcMapFeatureEventArgs args){ MgResourceIdentifier resId = args.GetResourceIdentifier(); AcMapFeature mapFeature = args.GetFeature(); string featureClassName = mapFeature.GetClassDefinition().GetName();}

//Handling the FeatureInserted event //declare delegate objectprivate static FeatureInsertedHandler g_eventHandler = null;public bool RegisterEvent(){ AcMapFeatureService fs = AcMapServiceFactory.GetService(MgServiceType.FeatureService) as AcMapFeatureService; //Create an instance of the delegate g_eventHandler = new FeatureInsertedHandler(this.MyEventHandlerFunction); //Associate delegate with the event fs.FeatureInserted += g_eventHandler; }

//Implement handler functionprivate void MyEventHandlerFunction (object sender, AcMapFeatureEventArgs args){ MgResourceIdentifier resId = args.GetResourceIdentifier(); AcMapFeature mapFeature = args.GetFeature(); string featureClassName = mapFeature.GetClassDefinition().GetName();}

Page 70: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - "Beyond the Box” Expanding the Developers Toolbox 70

Q and A

Page 71: © 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API1 AutoCAD Map 3DPlatform API Training.

© 2007 Autodesk - AutoCAD Map 3D Geospatial Platform API 71

"Beyond the Box"

Expanding the Developers Toolbox

Gabriel Ajayi


Recommended