Upload
cordelia-parrish
View
219
Download
3
Embed Size (px)
Citation preview
Presented by : Olivia LinPresented 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
2
Preparation works
• Developed by – Microsoft Visual Studio– Language : C # , C ++– COM architecture
• SuperGIS Desktop
3
Source of Sample Code
• Supergeo Developer Network (SGDN)– http://sgdn.supergeotek.com/
4
r
5
In SGDN, you’ll find more:
6
Get starting from SGDN
7
Example-Simple Map Information Sample
• This sample contains: Toolbar Combo box Drop-down menu Button
8
Example -Simple Map Information Sample
9
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
10
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)
11
Simple Map Information Sample
• Step 3 Start to debug this application
• In SuperGIS Desktop, you’ll see
12
Live demonstration
13
14
Modify sample codes- Add a spatial query tool to toolbar
Modify sample codes- Add a spatial query tool to toolbar
• Drag a rectangle over features and then retrieve the attribute in a message window.
15
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
16
Add a class
17
Add a class
18
Add reference
• Add reference– SGDataAcess– SGMap– SuperGeo User Interface 1.0 Type
Library– using System.Runtime.InteropServices;– using System.Drawing
19
• Set the class to visible– [ComVisible(true)]
• query is a public class
• Inherit ITool, Icommand
20
Implement ITool
• Click on “SGCore” > Select “Implement interface SGCore.ITool”
21
Design this tool
22
SGCore.ITrackTarget
• Detect user’s action by SGCore.ITrackTarget TkTgt;
• The track can be a circle, a linestring, a polygon or a rectangle.
23
SGCore.ICommandTarget
• Set the button’s target map object
• SGCore.ICommandTarget pMapTgt;
24
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;• }• }
25
• public bool OnContextMenu(int x, int y)• {• return true;• }
• public void OnDblClick()• {• throw new NotImplementedException();• }
• public void OnHook(SGCore.ITrackTarget Hook)• {• TkTgt = Hook; • }
26
• public void OnKeyDown(short KeyCode, short Shift)• {• throw new NotImplementedException();• }
• public void OnKeyUp(short KeyCode, short Shift)• {• throw new NotImplementedException();• }
27
• 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();• }
28
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(); } }
29
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 layerDefine the map and the target layer
30
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 shapeDecide the queried shape
31
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(); } }
Set the query actionSet the query action
pSpQry is a query objectpSpQry is a query object
32
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 QueryExecute Spatial Query
33
• 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();• }
34
• public bool QueryDeactivate()• {• TkTgt = null;• return true; • }
35
Implement ICommand
• Click on “SGCore” > Select “Implement interface SGCore.ICommand”
36
Start to design
• public string Caption • {• get { return "Spatial Query"; }• }
• public bool Checked• {• get { return (TkTgt != null); }• }
37
• public bool Enabled• {• get { return true; } • }
• public string HelpFile• {• get { return "NO Help"; } • }
38
• 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;Declare Icon m_Icon = null;
39
• 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"; }• }
40
Add to the Toolbar
• //In SimpleMapInfoToolbar.cs, add query
• Query queryBtn = new Query();
• m_Cmd.Add(queryBtn);
41
Run this project
42
43
Live demonstration
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”
44
45
Live demonstration
Supergeo Technologies Inc.www.supergeotek.com
THANK YOU FOR JOINING THIS COURSETHANK YOU FOR JOINING THIS COURSE
46