ThinkGeo.com    |     Documentation    |     Premium Support

Proximity analysis

 hello forum,


 


i want to create an application in which nereast POI is displayed for the user(from its current location). is mapsuite provide any proximity analysis tool? to find nearest poi.



Hi Sarah,
 
Mapsuite provides the fuction you need, here is the sample code:
 

            InMemoryFeatureLayer imLayer = new InMemoryFeatureLayer();
            PointShape center = new PointShape(0, 0);
            Feature feature1 = new Feature(new PointShape(1, 0));
            Feature feature2 = new Feature(new PointShape(2, 0));

            imLayer.InternalFeatures.Add(feature1);//feature1 is the nearest one and should be found
            imLayer.InternalFeatures.Add(feature2);
            imLayer.FeatureSource.Open();
            Collection<Feature> featuresFound = imLayer.FeatureSource.GetFeaturesNearestTo(center, GeographyUnit.DecimalDegree, 1, ReturningColumnsType.NoColumns);
            Debug.WriteLine(featuresFound[0]);


 

Hope it helps,
 
Edgar


 hello forum, 


i want some information about mvc mobile edition. is this package can used for android mobile? 


 


 



Hi Sarah,
 
Our MVC Mobile Edition can properly support android mobile(android 2.1 and above), Here is a very detailed guide for you, please check it:
wiki.thinkgeo.com/wiki/Map_S…tart_Guide
 
hope it helps
 
Edgar

Thanks Edgar,


 


kindly help me to solve an other issue i want to use google map as baselayer. My shapefile's actual projection is in decimal degree. my code is as below:


 


   winformsMap1.MapUnit = GeographyUnit.DecimalDegree;



            winformsMap1.CurrentExtent = new RectangleShape(71.774270, 35.916971, 71.816231, 35.815550);



            

            //make a feature source layer set it zoom level 



            ShapeFileFeatureLayer layer1 = new ShapeFileFeatureLayer(@"C:\Users\HP\Desktop\Demo\Demo\bin\Debug\Roads\roads.shp");



            layer1.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad3;

            layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;



            LayerOverlay cty = new LayerOverlay();

            cty.Layers.Add("layer1", layer1);

            winformsMap1.Overlays.Add(cty);

            //define POI's layer

            ShapeFileFeatureLayer poilayer = new ShapeFileFeatureLayer(@"C:\Users\HP\Desktop\Demo\Demo\bin\Debug\POIs\Points.shp");

            poilayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital2;

            poilayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;





            LayerOverlay poi = new LayerOverlay();





            poi.Layers.Add("POI", poilayer);

            winformsMap1.Overlays.Add("Point of interest", poi);





            RoutingLayer routingLayer = new RoutingLayer();



            LayerOverlay routingOverlay = new LayerOverlay();

            routingOverlay.Layers.Add("RoutingLayer", routingLayer);

            winformsMap1.Overlays.Add("RoutingOverlay", routingOverlay);



            winformsMap1.MapClick += new EventHandler<mapclickwinformsmapeventargs>(winformsMap1_MapClick);



            InMemoryFeatureLayer point = new InMemoryFeatureLayer();



            point.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = PointType.Bitmap;

            point.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = new GeoImage(@"C:\Users\HP\Desktop\Demo\Demo\bin\Debug\POIs\point.bmp");

            point.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;



            LayerOverlay glayer = new LayerOverlay();



            glayer.Layers.Add("points", point);

            winformsMap1.Overlays.Add("Glayer", glayer);

            winformsMap1.MapUnit = GeographyUnit.Meter;





            

            GoogleMapsOverlay googleMapsOverlay = new GoogleMapsOverlay();

            googleMapsOverlay.CacheDirectory = "C:\\ImageCache";

            winformsMap1.Overlays.Add(googleMapsOverlay);

           



            winformsMap1.CurrentExtent = new RectangleShape(750563.693500, 3978400.923800, 754159.668800, 3967055.776800);



            winformsMap1.Refresh();</mapclickwinformsmapeventargs>


 


the above code gives following results


 



 


 



 Hi Sarah,
 
Seems like there are 2 issues in the code pasted:
 
 1. Please keep all the layers’ projection same, if there are some layers which has different projection from other layers, we should  apply the projectionInfo to it. So, if we would like to use GoogleMap as the base layer, we should apply the projection defined as following to other layers like ShapeFileFatureLayer:
 


//Setup Projection
                Proj4Projection proj4Projection = new Proj4Projection();
                proj4Projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
                proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();

                InMemoryFeatureLayer inmemoryFeatureLayer = new InMemoryFeatureLayer();
                //Add features to inmemoryFeaturelayer

                inmemoryFeatureLayer.FeatureSource.Projection = proj4Projection;


 
 
2. There is no need to set the MapUnit and CurrentExtent twice in the method, the second one will overwrite the one set previously.
 
Here is a post which is similar with yours, please check it.
 
gis.thinkgeo.com/Support/Dis…fault.aspx 
 
 
If any other problems, please feel free to let us know.
 
Thanks
 
Johnny

both shapes files have same projection(decimal) but google requires meter units


so thats y i set mapunit as meter units 



sorrry johnny i can't understand. my both shapefiles has same projection which in decimal unit. now what should i do next to add google layers as base map.


 


my application is routing application



 Hi Sarah,


 
I am sorry I didn’t explain the projection clearly. In general, applying a projection to a layer is like below:



            Proj4Projection proj4Projection = new Proj4Projection();
            proj4Projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
            proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();

            ShapeFileFeatureLayer pointShapeFileFeatureLayer = new ShapeFileFeatureLayer(pointShapeFilePath);
            pointShapeFileFeatureLayer.FeatureSource.Projection = proj4Projection;




 

the “InternalProjectionParametersString” property means your original layer’s projection string. And the “ExternalProjectionParametersString”means the target projection you want to translate.
The last sentence means applying the projection rule to the current shapeFileFeatureLayer.
 
So, your first step is applying the projection to all your shapeFileFeatureLayers (layer1 and poilayer in your code). I modified your code:

 


            winformsMap1.MapUnit = GeographyUnit.Meter;
            winformsMap1.CurrentExtent = new RectangleShape(750563.693500, 3978400.923800, 754159.668800, 3967055.776800);
            //make a feature source layer set it zoom level 

            Proj4Projection proj4Projection = new Proj4Projection();
            proj4Projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
            proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();

            ShapeFileFeatureLayer layer1 = new ShapeFileFeatureLayer(@"C:\Users\HP\Desktop\Demo\Demo\bin\Debug\Roads\roads.shp");
            layer1.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad3;
            layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            layer1.FeatureSource.Projection = proj4Projection;

            LayerOverlay cty = new LayerOverlay();
            cty.Layers.Add("layer1", layer1);
            winformsMap1.Overlays.Add(cty);
            //define POI's layer
            ShapeFileFeatureLayer poilayer = new ShapeFileFeatureLayer(@"C:\Users\HP\Desktop\Demo\Demo\bin\Debug\POIs\Points.shp");
            poilayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital2;
            poilayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            poilayer.FeatureSource.Projection = proj4Projection;

            LayerOverlay poi = new LayerOverlay();
            poi.Layers.Add("POI", poilayer);
            winformsMap1.Overlays.Add("Point of interest", poi);


            RoutingLayer routingLayer = new RoutingLayer();

            LayerOverlay routingOverlay = new LayerOverlay();
            routingOverlay.Layers.Add("RoutingLayer", routingLayer);
            winformsMap1.Overlays.Add("RoutingOverlay", routingOverlay);

            winformsMap1.MapClick += new EventHandler(winformsMap1_MapClick);

            InMemoryFeatureLayer point = new InMemoryFeatureLayer();
            point.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = PointType.Bitmap;
            point.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = new GeoImage(@"C:\Users\HP\Desktop\Demo\Demo\bin\Debug\POIs\point.bmp");
            point.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            LayerOverlay glayer = new LayerOverlay();

            glayer.Layers.Add("points", point);
            winformsMap1.Overlays.Add("Glayer", glayer);

            GoogleMapsOverlay googleMapsOverlay = new GoogleMapsOverlay();
            googleMapsOverlay.CacheDirectory = "C:\\ImageCache";
            winformsMap1.Overlays.Add(googleMapsOverlay);

            winformsMap1.Refresh();



 

A similar post is here, please check it.
gis.thinkgeo.com/Support/Dis...fault.aspx 
 
If any other problem, please feel free to let us know.
 
Thanks

Johnny