ThinkGeo.com    |     Documentation    |     Premium Support

How to plotting the point and display distance between two point

Hi Fathin,

Thanks for your code.

The “Rectangle” is key of feature but not its id, so the code should looks like:

            inMemoryLayer.Open();
        inMemoryLayer.EditTools.BeginTransaction();
        inMemoryLayer.EditTools.Delete(inMemoryLayer.InternalFeatures["Rectangle"].Id);
        inMemoryLayer.EditTools.CommitTransaction();
        inMemoryLayer.Close();

And if you upload the sample, you don’t need package the “packages” and “bin” and “obj” folders.

Regards,

Ethan

Hi Ethan,

May i know what i got it wrong, i can seem to perform the delete function for InmemoryFeatureLayer. It throw :

ArgumentException was unhandled

remarks

An item with the same key has already been added.

15floors.zip (13.3 KB)

Regards,

Fathin

Hi Fathin,

Please comment this line: Map1.MapClick+=Map1_MapClick;

You bind the event twice, so the same feature with same key “woi” is added twice.

Regards,

Ethan

Hi Ethan,

i already comment the line you mention. But how can i bind the Feature to button click? I try to use the id “woi” so that it can bind the:

inmemoryFeatureLayer.EditTools.Delete(inmemoryFeatureLayer.InternalFeatures[“woi”].Id);

to

inmemoryFeatureLayer.InternalFeatures.Add(“woi”,new Feature(e.WorldLocation));

but it still throw :

ArgumentException was unhandled

remarks

An item with the same key has already been added.

 private void Map1_MapClick(object sender, MapClickWpfMapEventArgs e)
    {
        _LastMapClickLocation = e.WorldLocation;
        LayerOverlay markerOverlay = (LayerOverlay)Map1.Overlays["MarkerOverlay"];
        InMemoryFeatureLayer inmemoryFeatureLayer = markerOverlay.Layers[0] as InMemoryFeatureLayer;
        
        MultipolygonShape buffer = e.WorldLocation.Buffer(350, GeographyUnit.Meter, DistanceUnit.Kilometer);

        inmemoryFeatureLayer.InternalFeatures.Add("woi",new Feature(e.WorldLocation));

        Map1.Refresh();
    }

    private void Plot_ButtonClick(object sender, RoutedEventArgs e)
    {
        inmemoryFeatureLayer.Open();
        inmemoryFeatureLayer.EditTools.BeginTransaction();
        inmemoryFeatureLayer.EditTools.Delete(inmemoryFeatureLayer.InternalFeatures["woi"].Id);
        inmemoryFeatureLayer.EditTools.CommitTransaction();
        inmemoryFeatureLayer.Close();
    }

Regards,

Fathin.

Hi Fathin,

I thought you want to delete the “woi” feature when you click the button.

But it looks you don’t want to delete specified feature.

In your logic, each time you click on map the Map1_MapClick will be fired and a new feature with same key “woi” will be added, that’s why you met the same exception.

Please let me know your delete logic, what’s your target here.

For example: you want to delete a feature in clicked point.

I want to know your delete scenario, so I can help you complete the logic here.

Regards,

Ethan

Hai Ethan,

Actually my logic for now , it just to delete the feature or i mean to clear all the feature that i just created by Map1_MapClick function.

Regards,

Fathin

Hi Fathin,

If your target is clear all features, that’s easy.

    inmemoryFeatureLayer.InternalFeatures.Add(new Feature(e.WorldLocation)); // Don't set key here





    private void Plot_ButtonClick(object sender, RoutedEventArgs e)
    {
        LayerOverlay markerOverlay = (LayerOverlay)Map1.Overlays["MarkerOverlay"];
        InMemoryFeatureLayer inmemoryFeatureLayer = markerOverlay.Layers[0] as InMemoryFeatureLayer;
        inmemoryFeatureLayer.Clear();

        Map1.Refresh();
   }

Wish that’s helpful.

Regards,

Ethan

Hi Ethan,

I try to use below code to select the marker that created using InmemoryFeatureLayer, so that i can delete the specific marker. I put the below code on the button click event, so that when i click it fire the mapclick event to select the marker and delete that marker. The problem is that is not successfull, the event does not fire instead it still create the new marker when i click on specific marker that i want to delete.

Collection neartestFeatures = inmemoryFeatureLayer.QueryTools.GetFeaturesNearestTo(e.WorldLocation, GeographyUnit.Meter, 1, ReturningColumnsType.AllColumns);
if (neartestFeatures.Count > 0)
{
inmemoryFeatureLayer.InternalFeatures.Remove(neartestFeatures[0]);
}

15floors.zip (14.6 KB)

Regards,

Fathin

Hi Fathin,

Your logic have problem, our GetFeaturesNearestTo return max to 10 features in your logic, but it’s not always equal 10.

For example, when I run it, the return features equal 6.

So your logic should looks like:
inmemoryFeatureLayer.InternalFeatures.Remove(neartestFeatures[neartestFeatures.Count - 1]);

And you bind the MapClick event multiply times, please view the modified sample here:
9408_27.zip (14.6 KB)

For make it works, I comment your path, you can modify it back.

Regards,

Ethan

HI Ethan,

Thank you it work. Then i need to select the specific marker that created by inememoryfeaturelayer to get the distance between 2 point. Did i need to make a new layer for it just for calculating the distance?

Regards,

Fathin

Hi Fathin,

You can create a new layer to save the result, that’s simpler, or you can directly add the line in currently layer, don’t forget assign line style, but if you have other line shape in the same layer, we don’t suggest you do it.

Regards,

Ethan

HI Ethan,

What the new layer that i need to create, it a inmemoryfeaturelayer or inmemorymarkeroverlay? Still need to apply the trackoverlay function for this new layer right to create line between two point?

Regards,

Ethan

Hi Fathin,

I think an inmemoryfeaturelayer is enough for your scenario, you can add it in the same overlay.

And I suggest you view our HowDoISamples, it contains many general scenario, it should be helpful for your project.

Regards,

Ethan