[fusion-trac] #343: Measure: Area is wrong when unit of Map CS is feet

Fusion trac_fusion at osgeo.org
Wed Dec 2 05:09:12 EST 2009


#343: Measure: Area is wrong when unit of Map CS is feet
--------------------------+-------------------------------------------------
 Reporter:  christinebao  |         Owner:  Christine Bao
     Type:  defect        |        Status:  new          
 Priority:  P2            |     Milestone:  Future       
Component:  Widgets       |       Version:  1.1.1        
 Severity:  Major         |    Resolution:               
 Keywords:  Measure       |   External_id:  1281984      
    State:  New           |       Browser:  All          
       Os:  All           |  
--------------------------+-------------------------------------------------
Comment (by christinebao):

 Tech diagnosis:[[BR]]
 The code for measure area is:[[BR]]

 {{{
     updateMarker: function(marker, geom) {
         if (!marker) {
             return;
         }
         var quantity, from, to;
         var v = geom.getVertices();
         var map = this.getMap();
         var proj = map.oMapOL.baseLayer.projection;
         if (geom.CLASS_NAME.indexOf('LineString') != -1) {
             from = this.getMap().geoToPix(v[0].x,v[0].y);
             to = this.getMap().geoToPix(v[1].x,v[1].y);
             at = {x: (from.x + to.x) / 2, y: (from.y + to.y) / 2};
             quantity = geom.getGeodesicLength(proj);

             measureUnits = Fusion.METERS;
             if (measureUnits != this.units) {
               quantity = Fusion.convert(measureUnits, this.units,
 quantity);
             }
         } else {
             var cg = geom.getCentroid();
             at = this.getMap().geoToPix(cg.x, cg.y);
             quantity = geom.getGeodesicArea(proj);
             //TODO: result is in square meters - convert to other units?
         }
         if (quantity > 1) {
             marker.setQuantity(quantity);
             this.positionMarker(marker, at);
         }
     },
 }}}
 [[BR]]
 Please note: there is a TODO here: result is in square meters - convert to
 other units?

 As the map unit is feet, and length is measured in feed, it's better to
 convert the area from square meters to square feets.

 Add the code to fix this defect:[[BR]]

 {{{
            quantity = geom.getGeodesicArea(proj);

             measureUnits = Fusion.METERS;
             if (measureUnits != this.units) {
                 var rate = Fusion.convert(measureUnits, this.units, 1);
                 quantity = quantity * rate * rate;
             }
 }}}

 In this way, the quantity is coverted to square feets if needed.

-- 
Ticket URL: <http://trac.osgeo.org/fusion/ticket/343#comment:1>
Fusion <http://trac.osgeo.org/fusion>
Fusion is a web-mapping application development framework for MapServer and MapGuide OS.


More information about the fusion-trac mailing list