Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample...

46
Presented by : Olivia Lin Presented by : Olivia Lin

Transcript of Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample...

Page 1: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Presented by : Olivia LinPresented by : Olivia Lin

Page 2: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

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

Page 3: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Preparation works

• Developed by – Microsoft Visual Studio– Language : C # , C ++– COM architecture

• SuperGIS Desktop

3

Page 4: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Source of Sample Code

• Supergeo Developer Network (SGDN)– http://sgdn.supergeotek.com/

4

Page 5: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

r

5

Page 6: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

In SGDN, you’ll find more:

6

Page 7: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Get starting from SGDN

7

Page 8: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Example-Simple Map Information Sample

• This sample contains: Toolbar Combo box Drop-down menu Button

8

Page 9: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Example -Simple Map Information Sample

9

Page 10: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

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

Page 11: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

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

Page 12: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Simple Map Information Sample

• Step 3 Start to debug this application

• In SuperGIS Desktop, you’ll see

12

Page 13: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Live demonstration

13

Page 14: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

14

Modify sample codes- Add a spatial query tool to toolbar

Page 15: 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 to toolbar

• Drag a rectangle over features and then retrieve the attribute in a message window.

15

Page 16: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

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

Page 17: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Add a class

17

Page 18: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Add a class

18

Page 19: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Add reference

• Add reference– SGDataAcess– SGMap– SuperGeo User Interface 1.0 Type

Library– using System.Runtime.InteropServices;– using System.Drawing

19

Page 20: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

• Set the class to visible– [ComVisible(true)]

• query is a public class

• Inherit ITool, Icommand

20

Page 21: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Implement ITool

• Click on “SGCore” > Select “Implement interface SGCore.ITool”

21

Page 22: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Design this tool

22

Page 23: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

SGCore.ITrackTarget

• Detect user’s action by SGCore.ITrackTarget TkTgt;

• The track can be a circle, a linestring, a polygon or a rectangle.

23

Page 24: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

SGCore.ICommandTarget

• Set the button’s target map object

• SGCore.ICommandTarget pMapTgt;

24

Page 25: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

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

Page 26: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

• public bool OnContextMenu(int x, int y)• {• return true;• }

• public void OnDblClick()• {• throw new NotImplementedException();• }

• public void OnHook(SGCore.ITrackTarget Hook)• {• TkTgt = Hook; • }

26

Page 27: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

• public void OnKeyDown(short KeyCode, short Shift)• {• throw new NotImplementedException();• }

• public void OnKeyUp(short KeyCode, short Shift)• {• throw new NotImplementedException();• }

27

Page 28: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

• 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

Page 29: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

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

Page 30: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

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

Page 31: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

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

Page 32: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

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

Page 33: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

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

Page 34: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

• 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

Page 35: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

• public bool QueryDeactivate()• {• TkTgt = null;• return true; • }

35

Page 36: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Implement ICommand

• Click on “SGCore” > Select “Implement interface SGCore.ICommand”

36

Page 37: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Start to design

• public string Caption • {• get { return "Spatial Query"; }• }

• public bool Checked• {• get { return (TkTgt != null); }• }

37

Page 38: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

• public bool Enabled• {• get { return true; } • }

• public string HelpFile• {• get { return "NO Help"; } • }

38

Page 39: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

• 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

Page 40: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

• 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

Page 41: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Add to the Toolbar

• //In SimpleMapInfoToolbar.cs, add query

• Query queryBtn = new Query();

• m_Cmd.Add(queryBtn);

41

Page 42: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Run this project

42

Page 43: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

43

Live demonstration

Page 44: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

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

Page 45: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

45

Live demonstration

Page 46: Presented by : Olivia Lin. Outline Preparation works –What software do I need? Source of sample codes –Online source: Supergeo Developer Network (SGDN)

Supergeo Technologies Inc.www.supergeotek.com

THANK YOU FOR JOINING THIS COURSETHANK YOU FOR JOINING THIS COURSE

46