460 likes | 470 Views
Create Your Own Application in SuperGIS Desktop. Presented by : Olivia Lin. Outline. Preparation works What software do I need? Source of sample codes Online source: Supergeo Developer Network (SGDN) Modify sample codes Add a spatial query tool Unregister this application.
E N D
Create Your Own Application in SuperGIS Desktop Presented by : Olivia Lin
Outline • Preparation works • What software do I need? • Source of sample codes • Online source: Supergeo Developer Network (SGDN) • Modify sample codes • Add a spatial query tool • Unregister this application
Preparation works • Developed by • Microsoft Visual Studio • Language : C # , C ++ • COM architecture • SuperGIS Desktop
Source of Sample Code • Supergeo Developer Network (SGDN) • http://sgdn.supergeotek.com/
Example-Simple Map Information Sample • This sample contains: • Toolbar • Combo box • Drop-down menu • Button
Simple Map Information Sample • Step 1 Search and download the code from SGDN • Resource Center > Supergeo Samples • Products: SuperGIS Desktop, SuperGIS Extension • Languages & Platforms: C # • Key words : map information
Simple Map Information Sample • Step 2 Set Start Action for application debugging • Select SuperGIS.exe for Start external program • C:\Program Files\Supergeo\SuperGIS Desktop\SuperGIS.exe (32-bit) • C:\Program Files (x86)\Supergeo\SuperGIS Desktop\SuperGIS.exe (64-bit)
Simple Map Information Sample • Step 3 Start to debug this application • In SuperGIS Desktop, you’ll see
Modify sample codes- Add a spatial query tool to toolbar • Drag a rectangle over features and then retrieve the attribute in a message window.
Important Factors in Designing Spatial Query • Add a class to inherit ITool & ICommand • Perform the main action of Spatial Query tool in SGCore.ITool.OnMouseDown
Add reference • Add reference • SGDataAcess • SGMap • SuperGeo User Interface 1.0 Type Library • using System.Runtime.InteropServices; • using System.Drawing
Set the class to visible • [ComVisible(true)] • query is a public class • Inherit ITool, Icommand
Implement ITool • Click on “SGCore” > Select “Implement interface SGCore.ITool”
SGCore.ITrackTarget • Detect user’s action by SGCore.ITrackTarget TkTgt; • The track can be a circle, a linestring, a polygon or a rectangle.
SGCore.ICommandTarget • Set the button’s target map object • SGCore.ICommandTarget pMapTgt;
Start to design • public IntPtr Cursor //mouse cursor style • { • get • { • System.Windows.Forms.Cursor m_cursor; • m_cursor = System.Windows.Forms.Cursors.Cross; • return (IntPtr)m_cursor.Handle; • } • }
public bool OnContextMenu(int x, int y) • { • return true; • } • public void OnDblClick() • { • throw new NotImplementedException(); • } • public void OnHook(SGCore.ITrackTarget Hook) • { • TkTgt = Hook; • }
public void OnKeyDown(short KeyCode, short Shift) • { • throw new NotImplementedException(); • } • public void OnKeyUp(short KeyCode, short Shift) • { • throw new NotImplementedException(); • }
public void OnMouseDown(short Button, short Shift, int x, int y) • { • // Edit the command here • } • public void OnMouseMove(short Button, short Shift, int x, int y) • { • throw new NotImplementedException(); • } • public void OnMouseUp(short Button, short Shift, int x, int y) • { • throw new NotImplementedException(); • }
public void OnMouseDown(short Button, short Shift, int x, int y) { SGCore.ILayerGroup LG = ((SuperObjects2.IMapCtrl)pMapTgt).Map as SGCore.ILayerGroup; SGMap.FeatureLayer plyr; plyr = (SGMap.FeatureLayer)LG.Layer[0]; //the tool for drag a rectangle SGUserInterface.TrackFeedbackNewEnvelope tk = new SGUserInterface.TrackFeedbackNewEnvelope(); SGSFCOMS.IGeometry pGeo; pGeo = TkTgt.Track((SGCore.ITrackFeedback)tk); //built the spatial query with intersect relationship SGDataAccess.BinarySpatialOperator pSpQry = new SGDataAccess.BinarySpatialOperator(); pSpQry.OperatorType = SGDataAccess.SGOBinarySpatialOperatorType.SGO_BSOT_Intersects; pSpQry.Geometry = pGeo; SGCore.IFeatureCursor pCur; SGCore.IFeature pFea; pCur = ((SGCore.IFeatureLayer)plyr).FeatureClass.Search((SGCore.IFeatureFilter)pSpQry); pFea = pCur.NextFeature(); while (!(pFea == null)) { System.Windows.Forms.MessageBox.Show(pFea[3].ToString()); //Indicate the field to display pFea = pCur.NextFeature(); } }
public void OnMouseDown(short Button, short Shift, int x, int y) { SGCore.ILayerGroup LG = ((SuperObjects2.IMapCtrl)pMapTgt).Map as SGCore.ILayerGroup; SGMap.FeatureLayer plyr; plyr = (SGMap.FeatureLayer)LG.Layer[0]; //the tool for drag a rectangle SGUserInterface.TrackFeedbackNewEnvelope tk = new SGUserInterface.TrackFeedbackNewEnvelope(); SGSFCOMS.IGeometry pGeo; pGeo = TkTgt.Track((SGCore.ITrackFeedback)tk); //built the spatial query with intersect relationship SGDataAccess.BinarySpatialOperator pSpQry = new SGDataAccess.BinarySpatialOperator(); pSpQry.OperatorType = SGDataAccess.SGOBinarySpatialOperatorType.SGO_BSOT_Intersects; pSpQry.Geometry = pGeo; SGCore.IFeatureCursor pCur; SGCore.IFeature pFea; pCur = ((SGCore.IFeatureLayer)plyr).FeatureClass.Search((SGCore.IFeatureFilter)pSpQry); pFea = pCur.NextFeature(); while (!(pFea == null)) { System.Windows.Forms.MessageBox.Show(pFea[3].ToString()); //Indicate the field to display pFea = pCur.NextFeature(); } } Define the map and the target layer
public void OnMouseDown(short Button, short Shift, int x, int y) { SGCore.ILayerGroup LG = ((SuperObjects2.IMapCtrl)pMapTgt).Map as SGCore.ILayerGroup; SGMap.FeatureLayer plyr; plyr = (SGMap.FeatureLayer)LG.Layer[0]; //the tool for drag a rectangle SGUserInterface.TrackFeedbackNewEnvelope tk = new SGUserInterface.TrackFeedbackNewEnvelope(); SGSFCOMS.IGeometry pGeo; pGeo = TkTgt.Track((SGCore.ITrackFeedback)tk); //built the spatial query with intersect relationship SGDataAccess.BinarySpatialOperator pSpQry = new SGDataAccess.BinarySpatialOperator(); pSpQry.OperatorType = SGDataAccess.SGOBinarySpatialOperatorType.SGO_BSOT_Intersects; pSpQry.Geometry = pGeo; SGCore.IFeatureCursor pCur; SGCore.IFeature pFea; pCur = ((SGCore.IFeatureLayer)plyr).FeatureClass.Search((SGCore.IFeatureFilter)pSpQry); pFea = pCur.NextFeature(); while (!(pFea == null)) { System.Windows.Forms.MessageBox.Show(pFea[3].ToString()); //Indicate the field to display pFea = pCur.NextFeature(); } } Decide the queried shape
public void OnMouseDown(short Button, short Shift, int x, int y) { SGCore.ILayerGroup LG = ((SuperObjects2.IMapCtrl)pMapTgt).Map as SGCore.ILayerGroup; SGMap.FeatureLayer plyr; plyr = (SGMap.FeatureLayer)LG.Layer[0]; //the tool for drag a rectangle SGUserInterface.TrackFeedbackNewEnvelope tk = new SGUserInterface.TrackFeedbackNewEnvelope(); SGSFCOMS.IGeometry pGeo; pGeo = TkTgt.Track((SGCore.ITrackFeedback)tk); //built the spatial query with intersect relationship SGDataAccess.BinarySpatialOperator pSpQry = new SGDataAccess.BinarySpatialOperator(); pSpQry.OperatorType = SGDataAccess.SGOBinarySpatialOperatorType.SGO_BSOT_Intersects; pSpQry.Geometry = pGeo; SGCore.IFeatureCursor pCur; SGCore.IFeature pFea; pCur = ((SGCore.IFeatureLayer)plyr).FeatureClass.Search((SGCore.IFeatureFilter)pSpQry); pFea = pCur.NextFeature(); while (!(pFea == null)) { System.Windows.Forms.MessageBox.Show(pFea[3].ToString()); //Indicate the field to display pFea = pCur.NextFeature(); } } pSpQry is a query object Set the query action
public void OnMouseDown(short Button, short Shift, int x, int y) { SGCore.ILayerGroup LG = ((SuperObjects2.IMapCtrl)pMapTgt).Map as SGCore.ILayerGroup; SGMap.FeatureLayer plyr; plyr = (SGMap.FeatureLayer)LG.Layer[0]; //the tool for drag a rectangle SGUserInterface.TrackFeedbackNewEnvelope tk = new SGUserInterface.TrackFeedbackNewEnvelope(); SGSFCOMS.IGeometry pGeo; pGeo = TkTgt.Track((SGCore.ITrackFeedback)tk); //built the spatial query with intersect relationship SGDataAccess.BinarySpatialOperator pSpQry = new SGDataAccess.BinarySpatialOperator(); pSpQry.OperatorType = SGDataAccess.SGOBinarySpatialOperatorType.SGO_BSOT_Intersects; pSpQry.Geometry = pGeo; SGCore.IFeatureCursor pCur; SGCore.IFeature pFea; pCur = ((SGCore.IFeatureLayer)plyr).FeatureClass.Search((SGCore.IFeatureFilter)pSpQry); pFea = pCur.NextFeature(); while (!(pFea == null)) { System.Windows.Forms.MessageBox.Show(pFea[3].ToString()); //Indicate the field to display pFea = pCur.NextFeature(); } } Execute Spatial Query
public void OnMouseDown(short Button, short Shift, int x, int y) • { • // Edit the command here • } • public void OnMouseMove(short Button, short Shift, int x, int y) • { • throw new NotImplementedException(); • } • public void OnMouseUp(short Button, short Shift, int x, int y) • { • throw new NotImplementedException(); • }
public bool QueryDeactivate() • { • TkTgt = null; • return true; • }
Implement ICommand • Click on “SGCore” > Select “Implement interface SGCore.ICommand”
Start to design • public string Caption • { • get { return "Spatial Query"; } • } • public bool Checked • { • get { return (TkTgt != null); } • }
public bool Enabled • { • get { return true; } • } • public string HelpFile • { • get { return "NO Help"; } • }
public IntPtr Image • { • get { return m_Icon.Handle; } • } • public int HelpTopicID • { • get { return 0; } • } • public string Name • { • get { return "Spatial Query"; } • } Declare Icon m_Icon = null;
public void OnCommand(SGCore.ICommandTarget Parent) • { • pMapTgt = Parent; • // The button of the target map • // Use pMapTgt (ICommandTarget) to catch Parent • } • public string ToolTip • { • get { return "Spatial Query"; } • }
Add to the Toolbar • //In SimpleMapInfoToolbar.cs, add query • Query queryBtn = new Query(); • m_Cmd.Add(queryBtn);
Unregister this application • In Windows Command Prompt, under C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ • For C# > RegAsm.exe /u“<path>/<filename>.dll” • For C++ > Regsvr32 /u “<path>/<filename>.dll”
Supergeo Technologies Inc.www.supergeotek.com THANK YOU FOR JOINING THIS COURSE