The C # language implements the set data source functionality for ArcGIS data sources reset

Source: Internet
Author: User

1. Need to: Reset the data source based on the selected MXD path and destination data source path. Here with (. MDB, for example);

The main use of the interface:

(1) imapdocument (2)IMapControl2 (3)iworkspacefactory (4)Iworkspace (5) ienumdataset

(6) Idataset (7)ispatialreference (8)UID (9)Ienumlayer (Ten) ifeatureworkspace

Now a brief introduction to the above 10 interfaces common methods:

1, Imapdocument

(1), ActiveView, view of the map document;

(2), close, closes the map document;

(3), Documentfilename, the file name of the map document;

(4), DocumentType, type of map document,


(5), ismapdocument, determine whether it is a map document; ispasswordprotected: Password protected

(6), IsPresent, whether it exists, whether isreadonly is read-only. (A read-only document cannot be saved)

(7), layer, gets the layers in the map document. Returns the Ilayer type, parameter get_layer (intmapindex,intlayerindex)

(8), map, used to get IMAP objects, Mapcount: contains several Map objects

(9), New, create a mapdocument,

(10), open, opens a map document, opens according to the path. public void Open (string sdocument,string bspassword);

(11), save, for saving mapdocument,public void Save (bool Buserelativepaths,bool bcreatethumnbail);

(12), usesrelativepaths, specifying the path to the Mapdocument


2,IMapControl2 method is more, the function is clear, here is just a list;

(1), ActiveView, AddLayer, Addlayerfromfile, Centerat (for positioning), checkmxfile (checking an mxd path)

(2), clearlayers (clear all layers in map), Currenttool (tool on map), Deletelayer (delete layer)

(3), Drawshape (Draw a geometry on map), DrawText (draw text in geometry), flashshape (flashing)

(4), Frommappoint (convert point on map), Tomappoint (Convert to point on map), fullextent (full screen)

(5), hWnd: Handle, LayerCount (number of layers), loadmxfile (loading an mxd by path), Mapscale: Scale bar

(6), mapunits (map unit), MouseIcon (mouse shape), Movelayerto (move layer), refresh (refresh)

(7) Spatialreference (spatial reference), trackcircle (Draw circle), Trackline (line), Trackpolygon (Polygon)


3,iworkspacefactory workspace Factory, used to create the interface of the workspace, iworkspace inherit from it

(1), Copy, assign a work space

(2), create, creates a new workspace by path, file name, database connection

(3), GETCLASSID, factory ID

(4), Getworkspacename, get the name of the working space

(5), isworkspace, whether it is a working space

(6), move, moves a workspace to a specified folder

public bool Move (Iworkspacename workspacename,string destinationfolder);

(7), open, opens a working space public iworkspace Open (Ipropertyset connectionproperties,int hWnd);

(8), Openfromfile, open a workspace with the given filename

Public Iworkspace openfromfile (string filename,int hWnd);

(9) Readconnectionpropertiesfromfile, read connection properties according to file name

Public Ipropertyset Readconnectionpropertiesfromfile (string fileName);

(Workspacetype), type of work space,


4.Iworkspace working space for data Operation

(1), connectionproperties, connection properties, returns a Ipropertyset type

(2), Datasetnames, the name of the dataset in the workspace

(3), Datasets, feature set in Workspace executesql: Executes an SQL statement Exists: exists

(4), Isdirectory, is the system path PathName: The full name of the workspace path type: type


5,Ienumdataset

(1) Next, Next Reset: Reset DataSet

Classes such as: Ienumdataset Penumdataset = Pworkspace.get_datasets (Esridatasettype.esridtfeaturedataset);


6,Ifeatureworkspace

(1), Createfeatureclass, create a Featureclass

(2), Createfeaturedataset, create a dataset

Public Ifeaturedataset Createfeaturedataset (string Name, ispatialreference spatialreference);

(3), Openfeatureclass, open an existing Featureclass

Public Ifeatureclass Openfeatureclass (string Name);


Note: Other interfaces are available in other articles, or view arcengine's help documentation

Requirements Implementation code:

 private void Setdatasource (String smxdpath, String stargetpath) {////gets mapdocment imapdocum            ent pmapdocument = new Mapdocumentclass ();            Pmapdocument.open (Smxdpath, "");            Create a mapcontrol IMapControl2 Pmapcontrol = new Mapcontrolclass ();            string sfilename = Smxdpath;            Pmapcontrol.loadmxfile (sfilename, NULL, NULL);            Create a workspace iworkspacefactory pworkfactory = new Accessworkspacefactoryclass ();            Iworkspace pworkspace = pworkfactory.openfromfile (stargetpath, 0); Get all datasets in the workspace ienumdataset penumdataset = pworkspace.get_datasets (Esridatasettype.esridtfeaturedataset)            ;            Idataset Pdataset = Penumdataset.next (); Ispatialreference PRef = (pdataset as Igeodataset).            Spatialreference; String Sdistrictcode = String.            Empty; String Sscale = String.            Empty; if (pdataset! = null) {UIDUID = new Uidclass (); Uid. Value = "{" + typeof (Ifeaturelayer). Guid.                ToString () + "}";                Ienumlayer Penumlayer = PMapControl.Map.get_Layers (uid, true);                Ifeaturelayer Pfealyr = Penumlayer.next () as Ifeaturelayer;                Ifeatureworkspace Pfeaclswks = pworkspace as Ifeatureworkspace; while (Pfealyr! = null) {String sdsname = ((Pfealyr as Idatalayer). DataSourceName as Idatasetname).                    Name;                        if ((Pworkspace as IWorkspace2). Get_nameexists (Esridatasettype.esridtfeatureclass, sdsname)) {                        Pfealyr.featureclass = Pfeaclswks.openfeatureclass (sdsname);                    Pfealyr.name = Pfealyr.name;                } Pfealyr = Penumlayer.next () as Ifeaturelayer; }<pre name= "code" class= "CSharp" >//freeing up resources to prevent Ox80040228, resource lock error
ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject (Pworkspace); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject (Pfeaclswks); PMapControl.Map.SpatialReference = PRef; Imxdcontents pmxdc; PMXDC = Pmapcontrol.map as imxdcontents; Pmapdocument.open (Pmapcontrol as IMapControl3). Documentfilename, ""); Pmapdocument.replacecontents (PMXDC); Pmapdocument.save (True, true); } }


At this point, you implement the set Data source functionality in ArcMap.


The C # language implements the set data source functionality for ArcGIS data sources reset

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.