1 / 71

AutoCAD Map 3DPlatform API Training

AutoCAD Map 3DPlatform API Training. Agenda. Overview Map Resources Working with Features. Overview. AutoCAD Map 3D 2009 API. Map 3D Platform API. Map LISP/ADSRX API. Map ObjectARX API. Map ActiveX API. Map .NET API. FDO API. AutoCAD API. Entities. Features. AcDb.

lou
Télécharger la présentation

AutoCAD Map 3DPlatform API Training

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AutoCAD Map 3DPlatform API Training

  2. Agenda • Overview • Map Resources • Working with Features

  3. Overview

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

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

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

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

  8. FDO Feature Service 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

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

  10. 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. MgPoint MgMultiPoint MgLineString MgMultiLineString MgPolygon MgMultiPolygon MgCurveString MgMultiCurveString MgCurvePolygon MgMultiCurvePolygon MgMultiGeometry 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

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

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

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

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

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

  17. Getting Started Development 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)

  18. Getting Started Map Platform API Geospatial Platform API FDO • Namespaces • Autodesk.Gis.Map.Platform • Autodesk.Gis.Map.Platform.Interop • OSGeo.MapGuide • OSGeo.FDO* • OSGeo.FDO.Common*

  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

  20. Map Resources

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

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

  25. 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 LayerDefinitionXML • 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 • <FeatureSourcexmlns: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>

  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-1.2.0.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 ResourceAddedHandlerg_eventHandler = null; public boolRegisterEvent() { AcMapResourceServicers= 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, AcMapResourceEventArgsargs) { MgResourceIdentifierresId = args.GetResourceIdentifier(); MessageBox.Show(resId.ToString() + “ added”); }

  36. MgMapBase AcMapMap MgLayerCollection MgLayerBase AcMapLayer 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() //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 //Adddinglayer definition to repository AcMapResourceService rs = (AcMapResourceService)AcMapServiceFactory.GetService(MgServiceType.ResourceService MgByteSourcelayer_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”); //Adddingnew 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. MgFeatureService AcMapFeatureService Creating the Feature Service • Feature service is created from AcMapServiceFactory object using the GetService method // Get the feature service AcMapFeatureServicefeatureService = 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 providerMgByteReader 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"); MgStringCollectionschemaNames = 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. ID GEOM SIZE VALUE OWNER Identity Geometry Data 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.

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

  49. MgPropertyDefinition 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

More Related