AutoCAD Map 3DPlatform API Training

Slides:



Advertisements
Similar presentations
EziLink RESULTS Training Session 1 – Show and Tell For the Ministry of Forests, Lands and Natural Resource Operations.
Advertisements

CC SQL Utilities.
© 2006 Autodesk1 EMIA Geospatial Tech Camp and Sales Camp 2008.
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Introduction to Structured Query Language (SQL)
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Introduction to Structured Query Language (SQL)
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Introduction to Structured Query Language (SQL)
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence.
A tour of new features introducing LINQ. Agenda of LINQ Presentation We have features for every step of the way LINQ Fundamentals Anonymous Functions/Lambda.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Introducing FDO Toolbox Jackie Ng. Presentation Overview What is FDO? What is FDO Toolbox? Major Features of FDO Toolbox Demos.
State of Connecticut Core-CT Project Query 4 hrs Updated 1/21/2011.
McGraw-Hill© 2007 The McGraw-Hill Companies, Inc. All rights reserved. 1-1.
JSP Standard Tag Library
Information storage: Introduction of database 10/7/2004 Xiangming Mu.
Databases and LINQ Visual Basic 2010 How to Program 1.
Project Implementation for COSC 5050 Distributed Database Applications Lab2.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to Databases Chapter 6: Understanding the SQL Language.
Part 06 – A More Complex Data Model Entity Framework and MVC NTPCUG Tom Perkins.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Data File Access API : Under the Hood Simon Horwith CTO Etrilogy Ltd.
David Blasby The Open Planning Project New York. Goals Explain what a WFS and WMS are, and when to use them Be able to create simple spatial web applications.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
6. Simple Features Specification Background information UML overview Simple features geometry.
© 2011 Autodesk High-End Infrastructure Modeling with Low-Cost Tools: Introducing AutoCAD® Map 3D 2012 Bradford Heasley, GISP Vice President, Brockwell.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Andrew S. Budarevsky Adaptive Application Data Management Overview.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
1 CS 430 Database Theory Winter 2005 Lecture 2: General Concepts.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
© 2011 Autodesk Storm and Sewer Planning with AutoCAD ® Map 3D and Autodesk ® Storm and Sanitary Analysis Tanya West, PE, LEED AP Autodesk Technical Specialist.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Database System Concepts and Architecture.
John Pickford IBM H11 Wednesday, October 4, :30. – 14:30. Platform: Informix Practical Applications of IDS Extensibility (Part 2 of 2)
Benjamin Post Cole Kelleher.  Availability  Data must maintain a specified level of availability to the users  Performance  Database requests must.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Session 1 Module 1: Introduction to Data Integrity
Hyperion Artifact Life Cycle Management Agenda  Overview  Demo  Tips & Tricks  Takeaways  Queries.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Experience with XML Schema Ashok Malhotra Schema Usage  Mapping XML Schema and XML documents controlled by the Schema to object classes and instances.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
2) Database System Concepts and Architecture. Slide 2- 2 Outline Data Models and Their Categories Schemas, Instances, and States Three-Schema Architecture.
Integrating and Extending Workflow 8 AA301 Carl Sykes Ed Heaney.
 CONACT UC:  Magnific training   
CHAPTER 9 File Storage Shared Preferences SQLite.
OOPSLA Lab1 Chapter 7 Java Binding Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
ASP.NET Programming with C# and SQL Server First Edition
Visual Basic 2010 How to Program
Physical Structure of GDB
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Database System Concepts and Architecture.
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Data Model.
Database Objects 1/12/2019 See scm-intranet.
Contents Preface I Introduction Lesson Objectives I-2
Chapter 8 Advanced SQL.
ESRM 250/CFR 520 Autumn 2009 Phil Hurvitz
Presentation transcript:

AutoCAD Map 3DPlatform API Training

Agenda Overview Map Resources Working with Features

Overview

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

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

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

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

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.

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

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

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

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

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

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>$

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

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

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)

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.

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

Map Resources

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

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

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

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); byteSink.ToFile(@"c:\FeatureResource.Xml"); }

Map Resources Feature 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

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="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> <Name>File</Name> <Value>C:\Data\SDF\Signals.sdf</Value> <ConfigurationDocument></ConfigurationDocument> <LongTransaction></LongTransaction> </FeatureSource>

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

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

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

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

Map Resources Layer Definition

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

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

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

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

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

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

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

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

Working with Features

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

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;

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

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

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

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

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

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

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

MgGeometricPropertyDefinition Defines a geometric property Important methods SetHasElevation() SetReadOnly() SetSpatialContextAssociation SetGeometryTypes() Types of geometric properties MgFeatureGeometricType Point – 1 Curve – 2 Surface – 4 Solid – 8

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

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;

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

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

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

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

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

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, 1000000) DATE > ‘1995-3-15’ ADDRESS NULL

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

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

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((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 filter query.SetFilter("Geometry inside GEOMFROMTEXT(" + areaWkt + ")"); // SPATIAL FILTER – using SetSpatialFilter MgGeometry aGeometryObject; query.SetSpatialFilter("SHPGEOM", aGeometryObject, MgFeatureSpatialOperations.Inside);

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

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

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

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

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

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

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

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

Q and A

"Beyond the Box" Expanding the Developers Toolbox Gabriel Ajayi