Geocoding with SharpMap

Topics: Algorithms, Data Access
Nov 10, 2010 at 8:51 PM
Edited Nov 10, 2010 at 8:53 PM

How would I geocode with shapefiles using SharpMap in C# project to get the long&lat coordinate of a street address. Do you know if this is possible? Thanks.

Mar 17, 2015 at 9:39 AM
lamlh123 wrote:
How would I geocode with shapefiles using SharpMap in C# project to get the long&lat coordinate of a street address. Do you know if this is possible? Thanks.
This question is interesting for me too. Any hints?

I would like to fill my db with geocode for given addresses in the db.

I have seen, most people work with javascript and google api.
Is there a solution in c# / sharpmap?

thanks in advance for any hints :)
Editor
Mar 20, 2015 at 4:10 PM
Try something like this for nominatum geocodes, google is a similar but you need a different request and the response is different. Bounding box is one of our objects, but you can replace it with a sharpmap envelope object, you can then zoom to the results by merging the returned bounding boxes together to get the overall bounding box:

public List<SearchResult> GetGeocodes(string searchText)
    {
        WebRequest request = WebRequest.Create("http://nominatim.openstreetmap.org/search?q=" + searchText.Replace(" ","+") + "&format=json&addressdetails=1&polygon=0");
        request.ContentType = "application/json; charset=utf-8";

        WebResponse response = request.GetResponse();
        Stream responseStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(responseStream);

       var obj = reader.ReadToEnd();
       var json = JsonConvert.DeserializeObject<SearchResults>(obj);

        var results = new List<SearchResult>();

            foreach (var place in json)
            {
                var geoCodeResult = new SearchResult
                {
                    SearchInfo = place.display_name,
                    Latitude = place.lat,
                    Longitude = place.lon,
                    BoundingBox = new BoundingBox()
                    {
                        Bottom = place.boundingbox[0],
                        Left = place.boundingbox[3],
                        Top = place.boundingbox[1],
                        Right = place.boundingbox[2],
                    }
                };

                results.Add(geoCodeResult);
            }
        return results;
    }
public class SearchResult
{
    public double? Latitude { get; set; }
    public double? Longitude { get; set; }
    public string SearchInfo { get; set; }
    public BoundingBox BoundingBox { get; set; }
}