Thread: [Shapedotnet-development] Exposing MapMetrics
Status: Beta
Brought to you by:
k5jvc
From: Rife, R. <ri...@pw...> - 2004-01-16 21:26:24
|
I found it hard to create a shapefile outside of the Map object's AddLayer method and later use the Map's InsertLayer method to add it to the map. This is mostly because of the Shapefile's contructor requiring a MapMetric object. I think it would be useful to" =20 1) expose the Map's _mapMetrics variable as a public property so it can be used in the creation of standalone Shapefile objects =20 and/or =20 2) have a Shapefile constructor that does not require a MapMetrics object and have a metrics property on the Shapefile that can be set during the InsertLayer method call on the Map =20 I prefer the 2nd approach mostly because it allows for the most flexibility. Later. =20 Ryan Rife Senior Software Developer Pacific Western Technologies |
From: John C. <jo...@k5...> - 2004-01-18 05:37:48
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> </head> <body text="#000000" bgcolor="#ffffff"> Hmm. It's difficult to create an IMapLayer (<font size="2"><span style="font-size: 10pt; font-family: Arial;">Shapefile object)</span></font> outside of the Map object because I didn't design it to work that way. I had intended for the Add method to be used when a new layer needs to be created. The insert method was put in only so that I could move layers up and down easily after they had been created with the Add method. See the MoveLayerUp( int index ) and the MoveLayerDown( int index ) methods in MapControl.cs for an example of this.<br> <br> I think exposing <font size="2"><span style="font-size: 10pt; font-family: Arial;">_mapMetrics as a public property would be dangerous because it holds information read directly from the shapefile and uses calculations made from this information to convert real coordinates into local (pixel) coordinates for the map as a whole (so your #2 would not work, all map layers must have access to these calculations). All layers need access to the *same* World2Pixel(...) and Pixel2World(...) methods. If it were public, it would open up the possibility of corrupting the information from outside the Map class in ways that I haven't considered yet. I had also envisioned the </span></font><font size="2"><span style="font-size: 10pt; font-family: Arial;">_mapMetrics object containing projection, datum, and ellipsiod information in the future.</span></font><br> <font size="2"><span style="font-size: 10pt; font-family: Arial;"><br> The Shapefile class exists only to be a IMapLayer, that's it. As a class that implements IMapLayer, it should only exist within the confines of a Map class collection. My goal with the IMapLayer interface was to make it easy to write new file format readers in the future. I didn't intend for these </span></font><font size="2"><span style="font-size: 10pt; font-family: Arial;">file format readers to be stand alone objects. You can see on line 40 in IMapLayer.cs my master plan:<br> <br> </span></font><font size="2">public enum LayerSubType { Shapefile, Mif, E00, GeoTIFF }</font><br> <br> These are the file formats that I would like SDN to support in the near future. As always, if you see a hole in my strategy, please tell me so we can discuss it. There's always a better way.<br> <br> Rife, Ryan wrote:<br> <blockquote type="cite" cite="mid...@or..."> <meta http-equiv="Content-Type" content="text/html; "> <meta name="Generator" content="Microsoft Word 11 (filtered medium)"> <style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} a:link, span.MsoHyperlink {color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline;} span.EmailStyle17 {mso-style-type:personal-compose; font-family:Arial; color:windowtext;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:1120145861; mso-list-type:hybrid; mso-list-template-ids:-1123529014 67698705 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l0:level1 {mso-level-text:"%1\)"; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in;} ol {margin-bottom:0in;} ul {margin-bottom:0in;} --> </style> <div class="Section1"> <p class="MsoNormal"><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">I found it hard to create a shapefile outside of the Map object’s AddLayer method and later use the Map’s InsertLayer method to add it to the map. This is mostly because of the Shapefile’s contructor requiring a MapMetric object. I think it would be useful to”<o:p></o:p></span></font></p> <p class="MsoNormal"><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;"><o:p> </o:p></span></font></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;"><span style="">1)<font size="1" face="Times New Roman"><span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-stretch: normal; font-size-adjust: none;"> </span></font></span></span></font><!--[endif]--><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">expose the Map’s _mapMetrics variable as a public property so it can be used in the creation of standalone Shapefile objects<o:p></o:p></span></font></p> <p class="MsoNormal" style="margin-left: 0.25in;"><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;"><o:p> </o:p></span></font></p> <p class="MsoNormal" style="margin-left: 0.25in;"><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">and/or<o:p></o:p></span></font></p> <p class="MsoNormal"><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;"><o:p> </o:p></span></font></p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;"><span style="">2)<font size="1" face="Times New Roman"><span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-stretch: normal; font-size-adjust: none;"> </span></font></span></span></font><!--[endif]--><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">have a Shapefile constructor that does not require a MapMetrics object and have a metrics property on the Shapefile that can be set during the InsertLayer method call on the Map<o:p></o:p></span></font></p> <p class="MsoNormal"><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;"><o:p> </o:p></span></font></p> <p class="MsoNormal"><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">I prefer the 2<sup>nd</sup> approach mostly because it allows for the most flexibility. Later.<o:p></o:p></span></font></p> <p class="MsoNormal"><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;"><o:p> </o:p></span></font></p> <p class="MsoNormal"><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">Ryan Rife<o:p></o:p></span></font></p> <p class="MsoNormal"><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">Senior Software Developer<o:p></o:p></span></font></p> <p class="MsoNormal"><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;">Pacific Western Technologies<o:p></o:p></span></font></p> </div> </blockquote> </body> </html> |
From: E. P. <er...@pe...> - 2004-01-18 11:11:20
|
Hi John, For certain tasks it needs the m_map and Canvas to be public, see the examples below. Any intents of changing them to a non-protected status? Also using an aditional add-layer method (see below),...think this would be interesting to fit in too. For an application one can add some layers by default when starting up. HTH, Me. // Modified in the control: public System.Windows.Forms.PictureBox Canvas; public Map m_map; // Example to draw upon the canvas // --> Needs m_map and Canvas set to public: private void DrawAtCenter (double ptX, double ptY) { // Center & Draw mapControl.m_map.Center(ptX, ptY); mapControl.Draw(); // Visualize point Graphics g; g = mapControl.Canvas.CreateGraphics(); g.CompositingMode = CompositingMode.SourceOver; g.SmoothingMode = SmoothingMode.HighQuality; g.TranslateTransform(mapControl.Width /2,mapControl.Height/2); Point[] curvePoints = { new Point( 0, 10), new Point( 3, 3), new Point( 10, 0), new Point( 3, -3), new Point( 0, -10), new Point( -3, -3), new Point( -10, 0), new Point( -3, 3), }; // Draw polygon g.DrawPolygon(new Pen(Color.Black,1), curvePoints); g.FillPolygon(Brushes.Chartreuse, curvePoints, FillMode.Winding); g.FillEllipse(Brushes.Red, -2, -2, 4, 4); g.Dispose(); } // Example for hardcoded zooming // --> Needs m_map and Canvas set to public: myRect = new GIS.RectangleD(); myPoint1 = new GIS.PointD(); myPoint2 = new GIS.PointD(); myPoint1.X = 3.3; myPoint1.Y = 53.7; myPoint2.X = 7.5; myPoint2.Y = 50.6; myRect.UL = myPoint1; myRect.LR = myPoint2; mapControl.m_map.ZoomArea(myRect); mapControl.Draw(); // GIS.Map.cs --> Add a map without dialog box [Description("Read file without dialog"), Browsable( false )] public void AddLayerFromString(string path_and_name_of_shapefile) { this.Cursor = Cursors.AppStarting; m_map.Add( path_and_name_of_shapefile ); this.Cursor = Cursors.Default; Draw(); } CalculateExtents is not used in the AddLayerFromString example above,... this would be something for the user to decide. |
From: John C. <jo...@k5...> - 2004-01-18 19:00:09
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> </head> <body text="#000000" bgcolor="#ffffff"> Yep, you're right they need to be public. It makes the control significantly easier to use and to maintain.<br> <br> I added the property "MapCanvas" to the control and it returns the PictureBox that the map is drawn to.<br> I added the property "MapCollection" to the control and it returns the Map object of the control.<br> <br> So your example will look like this now:<br> <br> <big><tt><font size="2"><big>private void <span class="139190511-18012004"> DrawAtCenter </span>(double ptX, double ptY)<br> {<br> // Center & Draw<br> mapControl.<b>MapCollection</b>.Center(ptX, ptY);<br> mapControl.Draw();<br> // Visualize point<br> Graphics g;<br> g = mapControl.<b>MapCanvas</b>.CreateGraphics();<br> g.CompositingMode = CompositingMode.SourceOver; <br> g.SmoothingMode = SmoothingMode.HighQuality;<br> g.TranslateTransform(mapControl.Width /2,mapControl.Height/2);<br> Point[] curvePoints =<br> {<br> new Point( 0, 10),<br> new Point( 3, 3),<br> new Point( 10, 0),<br> new Point( 3, -3),<br> new Point( 0, -10),<br> new Point( -3, -3),<br> new Point( -10, 0),<br> new Point( -3, 3),<br> };<br> // Draw polygon <br> g.DrawPolygon(new Pen(Color.Black,1), curvePoints);<br> g.FillPolygon(Brushes.Chartreuse, curvePoints, FillMode.Winding);<br> g.FillEllipse(Brushes.Red, -2, -2, 4, 4);<br> g.Dispose();<br> }</big></font></tt></big><br> <br> How's that?<br> <br> As for your last request, I added the ability to add a new layer by passing in a string in beta 1.<br> <br> Thanks!<br> John<br> <br> E. Perik wrote:<br> <blockquote type="cite" cite="mid000001c3ddb3$cc966a40$0a01a8c0@xp"> <meta http-equiv="Content-Type" content="text/html; "> <title>Message</title> <meta content="MSHTML 6.00.2800.1106" name="GENERATOR"> <div><font face="Arial"><font size="2"><span class="139190511-18012004">Hi John,</span></font></font></div> <div><font face="Arial"><font size="2"><span class="139190511-18012004"> </span></font></font></div> <div><font><font face="Arial"><font size="2">For certain tasks it needs the m_map and Canvas to be public, see the examples below. <br> Any intents of changing them to a non-protected status?<span class="139190511-18012004"> </span></font></font></font></div> <div> </div> <div><font><font face="Arial"><font size="2"><span class="139190511-18012004">Also using an aditional add-layer method (see below),...think this would be interesting to fit in too. For an application one can add some layers by default when starting up. </span></font></font></font></div> <div> </div> <div><font><font face="Arial"><font size="2"><span class="139190511-18012004">HTH,</span></font></font></font></div> <div> </div> <div><font><font face="Arial"><font size="2"><span class="139190511-18012004">Me. </span></font></font></font></div> <div> </div> <blockquote dir="ltr" style="margin-right: 0px;"> <div><font face="Arial"><font size="2"><span class="139190511-18012004"> //</span><span class="139190511-18012004"> Modified in the control: </span><br> public System.Windows.Forms.PictureBox <strong>Canvas</strong>;<br> public Map <strong>m_map</strong>;</font></font></div> <div> </div> <div><br> <font face="Arial" size="2"> // Example to draw upon the canvas<br> // --> Needs <strong>m_map</strong> and <strong>Canvas</strong> set to public:<br> private void <span class="139190511-18012004"> DrawAtCenter </span>(double ptX, double ptY)<br> {<br> // Center & Draw<br> mapControl.m_map.Center(ptX, ptY);<br> mapControl.Draw();<br> // Visualize point<br> Graphics g;<br> g = mapControl.Canvas.CreateGraphics();<br> g.CompositingMode = CompositingMode.SourceOver; <br> g.SmoothingMode = SmoothingMode.HighQuality;<br> g.TranslateTransform(mapControl.Width /2,mapControl.Height/2);<br> Point[] curvePoints =<br> {<br> new Point( 0, 10),<br> new Point( 3, 3),<br> new Point( 10, 0),<br> new Point( 3, -3),<br> new Point( 0, -10),<br> new Point( -3, -3),<br> new Point( -10, 0),<br> new Point( -3, 3),<br> };<br> // Draw polygon <br> g.DrawPolygon(new Pen(Color.Black,1), curvePoints);<br> g.FillPolygon(Brushes.Chartreuse, curvePoints, FillMode.Winding);<br> g.FillEllipse(Brushes.Red, -2, -2, 4, 4);<br> g.Dispose();<br> }</font></div> <div> </div> <div><br> <font face="Arial" size="2"> // Example for hardcoded zooming<br> // --> Needs <strong>m_map</strong> and <strong>Canvas</strong> set to public:<br> myRect = new GIS.RectangleD();<br> myPoint1 = new GIS.PointD();<br> myPoint2 = new GIS.PointD();<br> myPoint1.X = 3.3;<br> myPoint1.Y = 53.7;<br> myPoint2.X = 7.5;<br> myPoint2.Y = 50.6;<br> myRect.UL = myPoint1;<br> myRect.LR = myPoint2;<br> mapControl.m_map.ZoomArea(myRect);<br> mapControl.Draw();</font></div> <div> </div> <div> </div> <div> </div> <div><font face="Arial" size="2"> // <strong>GIS.Map.cs</strong> --> Add a map without dialog box<br> [Description("Read file without dialog"), <br> Browsable( false )]<br> public void AddLayerFromString(string path_and_name_of_shapefile)<br> {<br> this.Cursor = Cursors.AppStarting;<br> m_map.Add( path_and_name_of_shapefile );<br> this.Cursor = Cursors.Default; <br> Draw();<br> }</font></div> </blockquote> <div> </div> <div><font face="Arial"><font size="2">CalculateExtents is not used in the AddLayerFromString example above,... this would be something for the user to decide.<span class="139190511-18012004"> </span></font></font></div> <div> </div> <div> </div> </blockquote> </body> </html> |
From: E. P. <er...@pe...> - 2004-01-18 19:45:59
|
Hi John, ok, good thinking there :D It seems i overlooked the 'adding layer by string',... think i used in 0.8 or 0.9. BTW, could you post a snippet on handling the stretch/warp as you tried, but where not satisfied with? Me. -----Original Message----- From: sha...@li... [mailto:sha...@li...] On Behalf Of John Coleman Sent: zondag 18 januari 2004 20:01 To: sha...@li... Subject: Re: [Shapedotnet-development] m_map and Canvas to be public Yep, you're right they need to be public. It makes the control significantly easier to use and to maintain. I added the property "MapCanvas" to the control and it returns the PictureBox that the map is drawn to. I added the property "MapCollection" to the control and it returns the Map object of the control. So your example will look like this now: private void DrawAtCenter (double ptX, double ptY) { // Center & Draw mapControl.MapCollection.Center(ptX, ptY); mapControl.Draw(); // Visualize point Graphics g; g = mapControl.MapCanvas.CreateGraphics(); g.CompositingMode = CompositingMode.SourceOver; g.SmoothingMode = SmoothingMode.HighQuality; g.TranslateTransform(mapControl.Width /2,mapControl.Height/2); Point[] curvePoints = { new Point( 0, 10), new Point( 3, 3), new Point( 10, 0), new Point( 3, -3), new Point( 0, -10), new Point( -3, -3), new Point( -10, 0), new Point( -3, 3), }; // Draw polygon g.DrawPolygon(new Pen(Color.Black,1), curvePoints); g.FillPolygon(Brushes.Chartreuse, curvePoints, FillMode.Winding); g.FillEllipse(Brushes.Red, -2, -2, 4, 4); g.Dispose(); } How's that? As for your last request, I added the ability to add a new layer by passing in a string in beta 1. Thanks! John E. Perik wrote: Hi John, For certain tasks it needs the m_map and Canvas to be public, see the examples below. Any intents of changing them to a non-protected status? Also using an aditional add-layer method (see below),...think this would be interesting to fit in too. For an application one can add some layers by default when starting up. HTH, Me. // Modified in the control: public System.Windows.Forms.PictureBox Canvas; public Map m_map; // Example to draw upon the canvas // --> Needs m_map and Canvas set to public: private void DrawAtCenter (double ptX, double ptY) { // Center & Draw mapControl.m_map.Center(ptX, ptY); mapControl.Draw(); // Visualize point Graphics g; g = mapControl.Canvas.CreateGraphics(); g.CompositingMode = CompositingMode.SourceOver; g.SmoothingMode = SmoothingMode.HighQuality; g.TranslateTransform(mapControl.Width /2,mapControl.Height/2); Point[] curvePoints = { new Point( 0, 10), new Point( 3, 3), new Point( 10, 0), new Point( 3, -3), new Point( 0, -10), new Point( -3, -3), new Point( -10, 0), new Point( -3, 3), }; // Draw polygon g.DrawPolygon(new Pen(Color.Black,1), curvePoints); g.FillPolygon(Brushes.Chartreuse, curvePoints, FillMode.Winding); g.FillEllipse(Brushes.Red, -2, -2, 4, 4); g.Dispose(); } // Example for hardcoded zooming // --> Needs m_map and Canvas set to public: myRect = new GIS.RectangleD(); myPoint1 = new GIS.PointD(); myPoint2 = new GIS.PointD(); myPoint1.X = 3.3; myPoint1.Y = 53.7; myPoint2.X = 7.5; myPoint2.Y = 50.6; myRect.UL = myPoint1; myRect.LR = myPoint2; mapControl.m_map.ZoomArea(myRect); mapControl.Draw(); // GIS.Map.cs --> Add a map without dialog box [Description("Read file without dialog"), Browsable( false )] public void AddLayerFromString(string path_and_name_of_shapefile) { this.Cursor = Cursors.AppStarting; m_map.Add( path_and_name_of_shapefile ); this.Cursor = Cursors.Default; Draw(); } CalculateExtents is not used in the AddLayerFromString example above,... this would be something for the user to decide. ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ Shapedotnet-development mailing list Sha...@li... https://lists.sourceforge.net/lists/listinfo/shapedotnet-development |