I want to use a dataset of historical counties and get a parish and county based on a lat lon position.

An extract of the data is here:


The shape data looks like this:

enter image description here

So the idea is someone selects point on a map (Mapbox), this returns a lat, lon which I then want to use to dynamically return a 'county' and 'parish' based on the data in the csv.

I will need to use a system to determine if the lat, lon is within the area of a parish.

Does anyone has some pointers to get me started?

UPDATE: Created example based on Bill's answer.


Using TURF js, you can determine if your point is inside a polygon. "turf.inside(point, polygon)". Basically using the eachLayer function, you can loop through each poly and determine if the point is inside. If it is turf.inside will return TRUE.

Working example: The JSON file I used. http://www.gistechsolutions.com/leaflet/DEMO/Search/usa.json

<!DOCTYPE html>
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
    <script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

    <script src="https://npmcdn.com/@turf/turf/turf.min.js"></script>


      #map {
        width: 800px;
        height: 600px;
        border: 1px solid black;
        z-index: 0;


<div id="map" ></div>

var url = 'usa.json';  // my GeoJSON data source, in this case a static file not a live PHP data feed.

    var map = L.map('map').setView([47.7541, -107.05078], 3); 

    var osm=new L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png',{ 
                attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'});

    var OpenStreetMap_BlackAndWhite = L.tileLayer('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', {
    maxZoom: 18,
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'

// Set style function that sets fill color property
function style(feature) {
    return {
        fillColor: 'green', 
        fillOpacity: 0.5,  
        weight: 2,
        opacity: 1,
        color: '#ffffff',
        dashArray: '3'

// Null variable that will hold layer
var stateLayer = L.geoJson(null, { style: style});

    $.getJSON(url, function(data) {


        lat = e.latlng.lat;
        lon = e.latlng.lng;

  var theMarker;
  var selPoly = [];

  function ProcessClick(lat,lon){
    if (theMarker != undefined) {
    theMarker = L.marker([lat,lon]).addTo(map);

    stateLayer.eachLayer(function (layer) {

        isInside =turf.inside(theMarker.toGeoJSON(), layer.toGeoJSON());

        if (isInside){


    var newgeojsonLayer = L.geoJson(selPoly, {
    color: 'orange',
          fillOpacity: .5,
          opacity: 1

var baseMaps = {
    "Open Street Map": osm,
    "OSM B&W":OpenStreetMap_BlackAndWhite

var overlayMaps = {
//Add layer control
L.control.layers(baseMaps, overlayMaps).addTo(map);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.