Presentation is loading. Please wait.

Presentation is loading. Please wait.

AutoCAD Map 3DPlatform API Training

Similar presentations


Presentation on theme: "AutoCAD Map 3DPlatform API Training"— Presentation transcript:

1 AutoCAD Map 3DPlatform API Training

2 Agenda Overview Map Resources Working with Features

3 Overview

4 AutoCAD Map 3D 2009 API FDO API AutoCAD API Map 3D Platform API
Map LISP/ADSRX API Map ObjectARX API Map ActiveX API Map .NET API AutoCAD API FDO API Entities Features AcDb FDO Data Store

5 The Geospatial APIs Map 3D Platform API MapGuide Geospatial Platform
Site Service Drawing Service Rendering Service Tiling Service Geospatial Platform Shared Code Shared Interface Geometry System Types Resource Service Collections Feature Service Coordinate System Exceptions Mapping Service FDO

6 Feature-Entity Service
API Components Exceptions Collections Map and Layers Geometry Resource Service Common Feature Service Feature-Entity Service Coordinate System

7 Resource Service Resources 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 SDF SHP Oracle Library:// LayerDef. FeatureSrc. DWG Database Repository

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 FDO is a set of APIs for manipulating and analyzing geographic data Feature Service API delegates a lot of its functionality to FDO Providers Provides consistent access to different data storage with a common general purpose abstraction layer.

9 Feature-Entity Service
New Enables AutoCAD Selection API support for Features Selection set management Support for feature highlighting AcMapFeatureEntityService

10 MgLayerGroupCollection
Map and Layers MgMapBase 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 AcMapMap MgLayerGroupCollection MgLayerCollection MgLayerGroup MgLayerBase AcMapLayerGroup AcMapLayer

11 Geometry Contains geometric object types and operations to
manipulate them Supports spatial comparisons between objects creation of new objects based on the intersection, difference, or union of existing objects creation of buffers around objects MgMultiPolygon MgPoint MgLineString MgPolygon MgCurveString MgCurvePolygon MgMultiPoint MgMultiLineString MgMultiCurveString MgMultiCurvePolygon MgMultiGeometry

12 Coordinate Systems Provides unified access to
coordinate system information Enables coordinate system transformations MgCoordinateSystem MgCoordinateSystemType MgCoordinateSystemTransform MgCoordinateSystemMeasure MgCoordinateSystemFactory

13 MgFeatureInformation
Utility Classes Common The Common classes provide a set of utility classes MgByte MgByteReader MgByteSink MgByteSource MgService MgColor MgMimeType MgDateTime MgFeatureInformation MgWarning

14 Utility Classes MgByteSource MgByteReader
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() MgByteSource MgByteReader MgByteSink File byte [ ] Other APIs A<{9>$

15 Utility Classes Collections Container for a set of objects of the same
type MgCollection MgStringCollection MgPolygonCollection MgLineStringCollection MgCoordinateCollection MgGeometryCollection MgIntCollection MgPointCollection MgPropertyCollection MgLinerRingCollection MgCurveRingCollection MgFeatureSchemaCollection

16 Utility Classes Exceptions
A set of classes representing all possible exceptions that can be generated by the application. 100+ classes MgFileNotFoundException MgGeometryException MgInvalidCoordinate- SystemException MgFileIoException MgFdoException MgOutOfMemoryException MgClassNotFoundException MgInvalidCastException MgResourcesException MgOverflowException

17 Getting Started Development Environment Assemblies Visual Studio 2005
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)

18 Geospatial Platform API
Getting Started Namespaces Autodesk.Gis.Map.Platform Autodesk.Gis.Map.Platform.Interop OSGeo.MapGuide OSGeo.FDO* OSGeo.FDO.Common* FDO Geospatial Platform API Map Platform API The API assembly is housed in Autodesk.Map.Platform.dll, located in the Map installation folder. Namespaces you will need for your applications: Autodesk.Gis.Map.Platform – the main Map 3D Platform API. This is the extension to the common Geospatial Platform API Autodesk.Gis.Map.Platform.Interop – component of the map 3D Platform API dedicated to interoperability with the AutoCAD API for user interaction with features (selection and highlighting) OSGeo.MapGuide – the Geospatial Platform API – component common to Map and MapGuide The FDO-related namespaces are only required if you will be using FDO functionality not exposed to the platform API, e.g. creating feature classes and data stores.

19 Getting Started DEMO – 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 acmgd.dll required at least for command implementation

20 Map Resources

21 AcMapResourceService
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 MgResourceService AcMapResourceService

22 Library://SDF_1.LayerDefinition Library://SDF_1.FeatureSource
Map Resources LayerDefinition and FeatureSource Resource Identifier of the FeatureSource is used in LayerDefinition Library://SDF_1.LayerDefinition Library://SDF_1.FeatureSource Map Layers LayerDefinition .sdf FeatureSource Data Source

23 Map Resources Creating 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 // Get an MgService object from AcMapServiceFactory and cast it to AcMapResourceService AcMapResourceService resServ = (AcMapResourceService)AcMapServiceFactory.GetService(MgServiceType.ResourceService); // Create a resource Id for a layer definition resource MgResourceIdentifier LayerDefResId = new MgResourceIdentifier("Library://Data/Raster/Redding.LayerDefinition"); // Create a resource Id for a feature source resource MgResourceIdentifier FtrSrcResId = new MgResourceIdentifier("Library://Data/Raster/Redding.FeatureSource");

24 Map Resources Getting Resource Content
Get the XML content of a LayerDefinition or FeatureSource using MgResourceService::GetResourceContent //Get the content of a FeatureSource MgResourceIdentifier 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); }

25 Map Resources Feature Source
Describes the information required to connect to the data source See FeatureSource 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

26 Map Resources Feature 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=" xsi:noNamespaceSchemaLocation="FeatureSource xsd" version="1.0.0"> <Provider>OSGeo.SDF.3.3</Provider> <Parameter> <Name>ReadOnly</Name> <Value>false</Value> </Parameter> <Name>File</Name> <Value>C:\Data\SDF\Signals.sdf</Value> <ConfigurationDocument></ConfigurationDocument> <LongTransaction></LongTransaction> </FeatureSource>

27 Map Resources Creating 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 modify XmlDocument doc = new XmlDocument(); doc.Load(C:\XML\SampleFeatureSource.xml") // Make modifications XmlNode providerNode = doc.GetElementsByTagName(“Provider"); providerNode.InnerText = “OSGeo.SHP.3.3”; //Save changes into a memory stream MemoryStream 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];

28 Map Resources Creating 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 data MgByteSource byteSource = new MgByteSource(ftrSrc, ftrSrc.Length); byteSource.SetMimeType(MgMimeType.Xml); // Add to repository MgResourceIdentifier resId = new MgResourceIdentifier(“Library://Data/Raster/Redding.FeatureSource“); AcMapResourceService rs = AcMapServiceFactory.GetService(MgServiceType.ResourceService) as AcMapResourceService; rs.SetResource(resId, byteSource .GetReader(), null);

29 Map Resources Layer Definition
Specification of the data source and stylization information for a layer See LayerDefinition xsd in “<Map 3D 2009 SDK Folder>\Schema” Required for creating a layer

30 Map Resources Layer 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

31 Map Resources Layer Definition

32 Map Resources Creating 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 modify XmlDocument doc = new XmlDocument(); doc.Load(C:\XML\SampleLayerDefinition.xml") // Make modifications XmlNode ftrSrcNode = doc.GetElementsByTagName("ResourceId").Item(0); ftrSrcNode.InnerText = "Library://Data/Shp/Roads.FeatureSource”; //Save changes into a memory stream MemoryStream 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];

33 Map Resources Creating 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 data MgByteSource byteSource = new MgByteSource(bytes , bytes.Length); byteSource.SetMimeType(MgMimeType.Xml); // Add to repository MgResourceIdentifier resId = new MgResourceIdentifier(“Library://Data/Raster/Redding.LayerDefinition“); AcMapResourceService rs = AcMapServiceFactory.GetService(MgServiceType.ResourceService) as AcMapResourceService; rs.SetResource(resId, byteSource .GetReader(), null);

34 Resource Service Events
Occur when resource-related actions, such as resource addition, modification or removal occur Event functions are members of AcMapResourceService

35 ResourceService Events
//Handling the ResourceAdded event //declare delegate object private 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 function private void MyEventHandlerFunction (object sender, AcMapResourceEventArgs args) MgResourceIdentifier resId = args.GetResourceIdentifier(); MessageBox.Show(resId.ToString() + “ added”);

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() MgLayerCollection MgMapBase AcMapMap MgLayerBase AcMapLayer //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 content MgResourceIdentifier layerResId = layer.GetLayerDefinition(); AcMapResourceService rs = (AcMapResourceService)AcMapServiceFactory.GetService(MgServiceType.ResourceService); MgByteReader byteRdr = rs.GetResourceContent(layerResId);

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.ResourceService MgByteSource 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 layer AcMapLayer layer = AcMapLayer.Create(layerResId,rs); //NEW! Layer.SetName(“Roads”); //Addding new layer to map layer collection MgLayerCollection layers = (AcMapLayer) AcMapMap.GetCurrentMap().GetLayers(); Layers.Add(layer);

38 Map Events Triggered when layers or features are added to or removed from the map Event functions are members of AcMapMap

39 Map Resources DEMO – Creating Resources Connect to feature sources
Create layers

40 Working with Features

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

42 Creating the Feature Service
Feature service is created from AcMapServiceFactory object using the GetService method MgFeatureService AcMapFeatureService // Get the feature service AcMapFeatureService featureService = AcMapServiceFactory.GetService(ServiceType.FeatureService) as AcMapFeatureService;

43 FDO Registry Get FDO registry and list the providers with the GetFeatureProviders method // Get the registered feature providers MgByteReader reader = featureService.GetFeatureProviders(); String providers = reader.ToString();

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 FDO Provider Capabilities // Get the capabilities of a provider MgByteReader reader = featureService.GetCapabilities (fullProviderName);

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");

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 schema foreach( String schemaName in schemaNames) { if(schemaName.ToLower() == “reddingschema") schema = featureService.DescribeSchema(id, schemaName).GetItem(0); break; }

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 GEOM OWNER VALUE SIZE Geometry Identity Data Object property type contains one or more objects whose type is a feature class A feature class contains a set of properties Each property has a set of attributes corresponding to the type of data it contains

48 MgClassDefinition Sets class properties
Used to describe or create feature classes Important methods SetDefaultGeometryPropertyName() GetProperties() Returns MgPropertyDefinitionCollection GetIdentityProperties()

49 MgPropertyDefinition
The details of a feature class property Has 4 subclasses or types MgDataPropertyDefinition MgGeometricPropertyDefinition MgRasterPropertyDefinition MgObjectPropertyDefinition

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

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)...

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 definition foreach( 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;

53 Feature Properties MgPropertyCollection 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 Properties Nullable ID GEOM OWNER VALUE SIZE

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

55 Geometry Format Conversion
Use MgAgfReaderWriter to translate between binary AGF and MgGeometry, and MgWktReaderWriter to translate between AGF Text and MgGeometry // Binary AGF -> MgGeometry MgAgfReaderWriter agfRW = new MgAgfReaderWriter(); // assume byteRdr, an MgByteReader object, contains a (binary) geometry MgGeometry geom = agfRW.Read(byteRdr); // MgGeometry -> Binary AGF // assume geom, an MgGeometry is already defined MgByteReader byteRdr= agfRW.Write(geom); // AGF Text -> MgGeometry MgWktReaderWriter wktRW = new MgWktReaderWriter(); String wktStr = “POINT XY (1 -1)”; MgGeometry geom = wktRW.Read(wktStr); // MgGeometry -> AGF Text String wktStr = wktRW.Write(geom);

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

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

58 Filter String Examples
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 Filter String Examples YEAR > 1990 and Year < 2000 NAME like “Richmond%” RVALUE in (500000, ) DATE > ‘ ’ ADDRESS NULL

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

60 Spatial Filter Operations
Spatial Relationship Contains Crosses Disjoint Equals Intersects Overlaps Touches Within Inside Note: Supported operation is determined by provider’s capabilities Crosses Intersects Touches Within Disjoint Overlaps

61 Filter-based Selection
// Define a query option and specify it’s criteria using a basic filter MgFeatureQueryOptions query = new MgFeatureQueryOptions(); query.SetFilter("Year >= 1990"); // Get the features MgFeatureReader featureReader = layer.SelectFeatures(query); // SPATIAL FILTER – using SetFilter() //WKT representation of a geometry string areaWkt = "'POLYGON XY(( , , "; areaWkt += " , , ))'"; //spatial relationship inside a basic filter query.SetFilter("Geometry inside GEOMFROMTEXT(" + areaWkt + ")"); // SPATIAL FILTER – using SetSpatialFilter MgGeometry aGeometryObject; query.SetSpatialFilter("SHPGEOM", aGeometryObject, MgFeatureSpatialOperations.Inside);

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 MgByteReader MgByteReader 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);

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%'");

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", "GEOM INTERSECTS GEOMFROMTEXT ('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))')");

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 commands commands.Add(updateFeatures); commands.Add(insertFeatures); //Execute commands MgLayerCollection layers = AcMapMap.GetCurrentMap().GetLayers(); AcMapLayer rdLayer = (AcMapLayer)layers.GetItem("Roads"); rdLayer.UpdateFeatures(commands);

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);

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 set MgSelectionBase ss = new MgSelectionBase(map); //Add 2 features (ID = 4736,4709) to selection set ss.AddFeatureIdInt32(rdLayer, rdLayer.FeatureClassName, 4736); ss.AddFeatureIdInt32(rdLayer, rdLayer.FeatureClassName, 4709); //Highlight features AcMapFeatureEntityService.HighlightFeatures(ss);

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

69 Feature Service Events+
//Handling the FeatureInserted event //declare delegate object private 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 function private void MyEventHandlerFunction (object sender, AcMapFeatureEventArgs args) MgResourceIdentifier resId = args.GetResourceIdentifier(); AcMapFeature mapFeature = args.GetFeature(); string featureClassName = mapFeature.GetClassDefinition().GetName(); FeatureInserted

70 Q and A

71 "Beyond the Box" Expanding the Developers Toolbox Gabriel Ajayi


Download ppt "AutoCAD Map 3DPlatform API Training"

Similar presentations


Ads by Google