question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Any better way to handle time for linestring in geojson files?

See original GitHub issue

At the moment I figured out, we can add time as a property for point and polygons. Works great but for line strings we need to add times as many times as coordinates or else just the last point is displayed. This is cumbersome. Does anyone have a different approach?

Point Sample

   "type":"FeatureCollection",
   "crs":{  
      "type":"name",
      "properties":{  
         "name":"urn:ogc:def:crs:OGC:1.3:CRS84"
      }
   },
   "features":[  
      {  
         "type":"Feature",
         "properties":{  
            "ID":1,
            "Category":null,
            "Type":"Test",
            "Date":"20180101000000",
            "time":"2015-03-08T00:00:00.000Z"
         }
      }
   ]
}

Linestring Sample

   "type":"FeatureCollection",
   "crs":{  
      "type":"name",
      "properties":{  
         "name":"urn:ogc:def:crs:OGC:1.3:CRS84"
      }
   },
   "features":[  
      {  
         "type":"Feature",
         "properties":{  
            "ID":1,
            "Category":null,
            "Type":"Bike",
            "Date":"20181201000000",
            "time":"2017-09-08T00:00:00.000Z",
            "times":[  
               "2017-03-08T00:00:00.000Z",
               "2018-03-08T00:00:00.000Z",
               "2019-03-08T00:00:00.000Z",
               "2020-03-08T00:00:00.000Z",
               "2021-03-08T00:00:00.000Z",
               "2022-03-08T00:00:00.000Z",
               "2022-03-08T00:00:00.000Z",
               "2022-03-08T00:00:00.000Z",
               "2022-03-08T00:00:00.000Z",
               "2022-03-08T00:00:00.000Z",
               "2022-03-08T00:00:00.000Z",
               "2019-03-08T00:00:00.000Z",
               "2020-03-08T00:00:00.000Z",
               "2020-04-08T00:00:00.000Z",
               "2020-06-08T00:00:00.000Z",
               "2022-9-08T00:00:00.000Z",
               "2022-03-08T00:00:00.000Z",
               "2022-03-08T00:00:00.000Z",
               "2022-03-08T00:00:00.000Z"
            ]
         },
         "geometry":{  
            "type":"LineString",
            "coordinates":[  
               [  
                  144.66611709854402,
                  -37.900577963091273
               ],
               [  
                  144.66602796949803,
                  -37.900442408518742
               ],
               [  
                  144.66590379717303,
                  -37.900365586305668
               ],
               [  
                  144.66576112853602,
                  -37.900303624206259
               ],
               [  
                  144.66554465611304,
                  -37.900240128116373
               ],
               [  
                  144.66534036753902,
                  -37.900183918893688
               ],
               [  
                  144.66518118427402,
                  -37.90013647945878
               ],
               [  
                  144.66505050724803,
                  -37.900103552184376
               ],
               [  
                  144.66491364621902,
                  -37.900062765214692
               ],
               [  
                  144.66482396021803,
                  -37.900032461346385
               ],
               [  
                  144.66469208573804,
                  -37.8999824054616
               ],
               [  
                  144.66459597229104,
                  -37.899951376409859
               ],
               [  
                  144.66444721577102,
                  -37.89989803638057
               ],
               [  
                  144.66430606349104,
                  -37.899865072139342
               ],
               [  
                  144.66412351145203,
                  -37.89982319766478
               ],
               [  
                  144.66386013259702,
                  -37.89946918323816
               ],
               [  
                  144.66362211228403,
                  -37.899210914901786
               ],
               [  
                  144.66348071296702,
                  -37.89899193259587
               ],
               [  
                  144.66323273213405,
                  -37.898545654643044
               ]
            ]
         }
      }
   ]
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bielfronteracommented, Apr 11, 2017

I’ve checked the code and it’s not working as you expected with one time for the whole linestring. It is generating a new linestring with the first point.

But you can create a new class to override the method _getFeatureBetweenDates, and return the feature without modification if its time is active. Checkout this example

L.TimeDimension.Layer.BikeLayer = L.TimeDimension.Layer.GeoJson.extend({

    // Do not modify features. Just return the feature if it intersects
    // the time interval
    _getFeatureBetweenDates: function(feature, minTime, maxTime) {
        var featureStringTimes = this._getFeatureTimes(feature);
        if (featureStringTimes.length == 0) {
            return feature;
        }
        var featureTimes = [];
        for (var i = 0, l = featureStringTimes.length; i < l; i++) {
            var time = featureStringTimes[i]
            if (typeof time == 'string' || time instanceof String) {
                time = Date.parse(time.trim());
            }
            featureTimes.push(time);
        }

        if (featureTimes[0] > maxTime || featureTimes[l - 1] < minTime) {
            return null;
        }
        return feature;
    },

});

L.timeDimension.layer.bikeLayer = function(layer, options) {
    return new L.TimeDimension.Layer.BikeLayer(layer, options);
};

var map = L.map('map', {
    zoom: 17,
    fullscreenControl: true,
    center: [-37.9, 144.666],
    timeDimension: true,
    timeDimensionControl: true,    
});

$.getJSON("data/bike.geojson",function(bikeData){
    var geojsonLayer = L.geoJson(bikeData);
    var bikeTimeLayer = L.timeDimension.layer.bikeLayer(geojsonLayer, {
        waitForReady: true,
        updateTimeDimension: true
    });
    // geojsonLayer.addTo(map);
    bikeTimeLayer.addTo(map);
});

0reactions
rainiteshcommented, Apr 12, 2017

@bielfrontera that just worked perfectly as I expected. Thanks heaps 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Representing Time in GeoJSON? - GIS Stack Exchange
In my opinion the "right" way would be using properties unless you consider your timestamps to be coordinates in time ...
Read more >
More than you ever wanted to know about GeoJSON
LineString and Polygon geometries contain coordinates in an order: lines go in a certain direction, and polygon rings do too. The direction of ......
Read more >
more efficient way to search through geoJson in double for ...
I would like to find the Linestrings that starts or ends coordinates equals point coordinates. I mean, I need first iterate over point...
Read more >
A primer on GeoJSON standard and visualization tools
A LinearRing is a closed LineString with four or more positions. “Closed” simply means that the start and end point of the LinearRing...
Read more >
Chapter 7 GeoJSON | Introduction to Web Mapping
However, there are ways to reduce GeoJSON file size by simplifying its ... the geometry can consist of one or more shapes of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found