Hi
Need to ask
some questions regarding GetArea() function used to calculate area of shapes
Question 1:
I get values
for POLYGON even if I draw circle or rectangle shape and getting correct values
when I draw line or point?
Question 2:
I am calculating
area in square meter, how can I check if the calculated value using GetArea()
is correct or not?
Question 3:
Shapes disappear after calling controller action.Why?
I followed these
two samples for my shape calculation implementation
For drawing
shapes
And for
calling controller functions and area calculations
Here’s my controller
action
public void GetShapeArea(Map map, GeoCollection <object>args)
{
string json = args[0] as string;
Collection features = MapHelper.ConvertJsonToFeatures(json);
foreach (Feature feature in features)
{
var id = feature.Id;
var name =feature.ToString();
if (name.Contains("POLYGON")) {
PolygonShape polygon = new PolygonShape(name);
double area = polygon.GetArea(GeographyUnit.Meter, AreaUnit.SquareMeters);
}
else if (name.Contains("LINESTRING"))
{
//do calculations
}
else if (name.Contains("POINT"))
{
PointShape point = new PointShape(name);
MultipolygonShape areaShape =point.Buffer(1.0,GeographyUnit.Meter,DistanceUnit.Meter);
double area =areaShape.GetArea(GeographyUnit.Meter, AreaUnit.SquareMeters);
}
}
}
this in cshtml file of map
@{Html.ThinkGeo().Map(Model).OnClientClick(“mapClick”).OnClientTrackShapeFinished(“trackShapeFinished”)
.CustomOverlays(overlays =>
{
overlays.WorldMapKitWmsWebOverlay();
InMemoryFeatureLayer shapeLayer = new InMemoryFeatureLayer();
shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(180, 102, 255, 102), 10, GeoColor.StandardColors.DarkGreen, 1);
shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Green, 4, true);
shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(180, 102, 255, 102), GeoColor.StandardColors.DarkGreen, 1);
shapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
overlays.LayerOverlay("ShapeOverlay").IsBaseOverlay(false).Layer(shapeLayer);
})
.Render();
}
Controller action method call
function trackShapeFinished(e) {
// alert(e);
Map1.ajaxCallAction(“Map”, “GetShapeArea”, { ‘features’: e.features }, function (result) {
Map1.redrawLayer(“ShapeOverlay”);
Map1.clearEditingFeatures();
});
}
When I checked it gives me these values
For points it gives me this value
{POINT(64.17724609375
37.713623046875)}
For Rectangle shape this values comes
in feature variable
{POLYGON((64.7705078125
33.033447265625,64.7705078125 35.736083984375,68.74755859375
35.736083984375,68.74755859375 33.033447265625,64.7705078125 33.033447265625))}
For Circle shape this values comes in
feature variable
“POLYGON((65.97900390625
36.988525390625,66.3159264779742 37.3030446749779,66.5850155084922
37.6772508924864,66.775930057268 38.0967635080689,66.8813333852584
38.5454608871739,66.8971749016795 39.0060998411548,66.8228458259392
39.4609782733394,66.6612025827341 39.8926154606776,66.41845703125
40.284423828125,66.1039377468971 40.6213463998492,65.7297315293886
40.8904354303672,65.3102189138061 41.081349979143,64.8615215347011
41.1867533071334,64.4008825807202 41.2025948235545,63.9460041485356
41.1282657478142,63.5143669611974 40.9666225046091,63.12255859375
40.723876953125,62.7856360220258 40.4093576687721,62.5165469915078
40.0351514512636,62.325632442732 39.6156388356811,62.2202291147416
39.1669414565761,62.2043875983205 38.7063025025952,62.2787166740608
38.2514240704106,62.4403599172659 37.8197868830724,62.68310546875
37.427978515625,62.9976247531029 37.0910559439008,63.3718309706114
36.8219669133828,63.7913435861939 36.631052364607,64.2400409652989 36.5256490366166,64.7006799192798
36.5098075201955,65.1555583514644 36.5841365959358,65.5871955388026
36.7457798391409,65.97900390625 36.988525390625))”
For Line shape
this values comes in feature variable
“LINESTRING(64.638671875
36.636962890625,74.37255859375 37.647705078125,72.98828125
36.702880859375)”
And for Free hand Tool
“LINESTRING(67.78076171875
39.075927734375,67.7587890625 39.075927734375,67.73681640625
39.075927734375,67.71484375 39.075927734375,67.69287109375 39.053955078125,67.5830078125
38.966064453125,67.51708984375 38.944091796875,67.4951171875
38.922119140625,67.42919921875 38.856201171875,67.29736328125
38.768310546875,67.2314453125 38.746337890625,67.1435546875
38.636474609375,67.099609375 38.592529296875,67.03369140625 38.548583984375,66.98974609375
38.482666015625,66.9677734375 38.438720703125,66.8798828125
38.350830078125,66.81396484375 38.218994140625,66.77001953125
38.197021484375,66.68212890625 38.065185546875,66.59423828125
37.889404296875,66.572265625 37.779541015625,66.5283203125
37.691650390625,66.50634765625 37.625732421875,66.484375
37.537841796875,66.4404296875 37.427978515625,66.41845703125
37.340087890625,66.37451171875 37.274169921875,66.3525390625
37.208251953125,66.3525390625 37.164306640625,66.3525390625
37.098388671875,66.33056640625 36.922607421875,66.28662109375
36.900634765625,66.28662109375 36.834716796875,66.28662109375
36.768798828125,66.28662109375 36.746826171875,66.28662109375
36.702880859375,66.28662109375 36.636962890625,66.28662109375 36.593017578125,66.28662109375
36.549072265625,66.28662109375 36.483154296875,66.28662109375
36.417236328125,66.30859375 36.351318359375,66.33056640625
36.285400390625,66.37451171875 36.175537109375,66.41845703125
36.109619140625,66.4404296875 36.043701171875,66.5283203125
35.867919921875,66.68212890625 35.604248046875,66.72607421875
35.538330078125,66.81396484375 35.428466796875,66.8359375
35.406494140625,66.923828125 35.318603515625,67.07763671875
35.230712890625,67.20947265625 35.186767578125,67.25341796875 35.164794921875,67.36328125
35.142822265625,67.42919921875 35.142822265625,67.451171875
35.142822265625,67.4951171875 35.142822265625,67.5390625
35.098876953125,67.56103515625 35.098876953125,67.626953125
35.098876953125,67.6708984375 35.098876953125,67.73681640625
35.098876953125,67.78076171875 35.098876953125,67.86865234375
35.120849609375,67.95654296875 35.142822265625,68.06640625
35.142822265625,68.154296875 35.164794921875,68.30810546875
35.186767578125,68.39599609375 35.252685546875,68.41796875 35.274658203125,68.48388671875
35.274658203125,68.57177734375 35.296630859375,68.59375
35.340576171875,68.61572265625 35.362548828125,68.70361328125
35.384521484375,68.7255859375 35.384521484375,68.74755859375
35.406494140625,68.79150390625 35.428466796875,68.857421875
35.472412109375,68.87939453125 35.472412109375,68.9013671875
35.494384765625,68.96728515625 35.516357421875,69.0771484375
35.604248046875,69.27490234375 35.736083984375,69.31884765625
35.802001953125,69.384765625 35.823974609375,69.45068359375 35.889892578125,69.5166015625
35.933837890625,69.53857421875 35.955810546875,69.560546875
35.977783203125,69.6484375 36.021728515625,69.6923828125
36.087646484375,69.736328125 36.153564453125,69.80224609375
36.197509765625,69.82421875 36.263427734375,69.84619140625
36.285400390625,69.9560546875 36.417236328125,70.0439453125
36.571044921875,70.06591796875 36.614990234375,70.087890625
36.658935546875,70.10986328125 36.702880859375,70.15380859375
36.768798828125,70.17578125 36.834716796875,70.17578125 36.878662109375,70.19775390625
36.944580078125,70.19775390625 36.966552734375,70.263671875
37.054443359375,70.263671875 37.076416015625,70.263671875
37.098388671875,70.263671875 37.120361328125,70.263671875
37.142333984375,70.263671875 37.164306640625,70.263671875 37.208251953125,70.263671875
37.230224609375,70.263671875 37.252197265625,70.263671875
37.274169921875,70.263671875 37.318115234375,70.263671875
37.384033203125,70.263671875 37.406005859375,70.263671875
37.427978515625,70.263671875 37.493896484375,70.24169921875
37.537841796875,70.2197265625 37.603759765625,70.17578125
37.669677734375,70.15380859375 37.735595703125,70.15380859375
37.757568359375,70.1318359375 37.801513671875,70.0439453125
37.867431640625,70.0439453125 37.889404296875,70.02197265625 37.911376953125,70
37.933349609375,69.97802734375 37.933349609375,69.93408203125
37.955322265625,69.89013671875 37.977294921875,69.8681640625
38.021240234375,69.84619140625 38.043212890625,69.7802734375
38.065185546875,69.71435546875 38.087158203125,69.67041015625 38.131103515625,69.560546875
38.153076171875,69.49462890625 38.197021484375,69.31884765625
38.284912109375,69.18701171875 38.350830078125,69.0771484375
38.372802734375,68.9892578125 38.438720703125,68.9453125
38.460693359375,68.87939453125 38.482666015625,68.83544921875
38.504638671875,68.76953125 38.526611328125,68.74755859375
38.526611328125,68.681640625 38.592529296875,68.65966796875
38.614501953125,68.61572265625 38.636474609375,68.59375
38.636474609375,68.5498046875 38.658447265625,68.4619140625 38.724365234375,68.3740234375
38.746337890625,68.330078125 38.768310546875,68.30810546875
38.790283203125,68.2421875 38.812255859375,68.22021484375
38.812255859375,68.1982421875 38.856201171875,68.17626953125
38.856201171875,68.154296875 38.878173828125,68.08837890625
38.878173828125,68.06640625 38.900146484375,68.04443359375
38.922119140625,68.0224609375 38.922119140625,68.00048828125
38.944091796875,67.978515625 38.944091796875,67.91259765625
38.966064453125,67.890625 39.010009765625,67.86865234375 39.010009765625,67.8466796875
39.031982421875,67.82470703125 39.031982421875,67.802734375
39.031982421875,67.7587890625 39.031982421875,67.73681640625
39.031982421875,67.71484375 39.031982421875,67.69287109375
39.031982421875)”
Can u tell me where am i wrong or missing something