FusionTables Heatmap Layer Weighting - heatmap

Is it possible to weight results within a FusionTables heatmap layer? For example, in my FusionTable dataset I have latitude, longitude, and counts. I'm not sure how to modify my layer to be weighted by my count field.
Here's a snippet of my layer:
layer1 = new google.maps.FusionTablesLayer({
query: {
select: "'col1'",
from: 'xxxxxxxxxxxxxxxxxxxxxx'
},
heatmap: {
enabled: true
}
});

This currently is not possible with a FusionTablesHeatMap. You may use the data from the FusionTable and create a HeatMap-Layer(where weighted locations are supported), but of course it will depend on the amount of data if it's realizable.

Related

Raster to Point conversion: how to convert every single pixel? on Google Earth Engine

Good day. I am trying to convert a raster to points using Google Earth Engine. My raster has one band (clusters) and it has been clipped to my ROI. I am aware of the reduceToVectors function on Google Earth Engine, but as I understand, this function creates areas with the same adjacent value, whereas what I want is to create as many points as there are pixels.
So far, I have tried different versions of:
var vectors = image.reduceToVectors({
reducer : null,
geometry : treat,
scale:30,
crs :image.projection().getInfo().crs,
geometryType : 'centroid',
labelProperty : 'null',
eightConnected: false,
maxPixels: 1e15
});
Thanks a lot for your help.
ee.Image.sample returns a point for every pixel.
var vectors = image.sample({
region: treat,
geometries: true, // if you want points
});
If you do not specify a scale and crs, it will use each pixel in the input image's original resolution. If you do, it will sample at the given scale instead.
Demonstration script:
var region = ee.Geometry.Polygon(
[[[-110.00683426856995, 40.00274575078824],
[-110.00683426856995, 39.99948706365032],
[-109.99576210975647, 39.99948706365032],
[-109.99576210975647, 40.00274575078824]]], null, false);
var image = ee.Image('CGIAR/SRTM90_V4');
Map.setCenter(-110, 40, 16);
Map.addLayer(image, {min: 1000, max: 2000}, 'SRTM');
var vectors = image.sample({
region: region,
geometries: true,
});
print(vectors);
Map.addLayer(ee.FeatureCollection([region]).style({"color": "white"}));
Map.addLayer(vectors);
https://code.earthengine.google.com/625a710d6d315bad1c2438c73bde843b

Why turfjs distance returns results different from Google Map geometry libs computeDistanceBetween?

I am puzzled on why the two libraries provide different results.
const CATA = {
lat: 57.312004,
lng: 25.289825
};
const PK = {
lat: 57.307953,
lng: 25.295025
};
const tCATA = turf.point([CATA.lat, CATA.lng]);
const tPK = turf.point([PK.lat, PK.lng]);
const tDistance = turf.distance(tCATA, tPK, { units: "meters" });
const gCATA = new google.maps.LatLng(CATA);
const gPK = new google.maps.LatLng(PK);
const gDistance = google.maps.geometry.spherical.computeDistanceBetween(
gCATA,
gPK
);
console.log(tDistance, gDistance); // 707.249063108749, 548.7294775022126
CodeSandbox: https://codesandbox.io/s/boring-hawking-b7uwh
Okay, one thing might be that turfjs uses different radius for Earth (6371008.8) than Google (6378137). But even providing turfs radius for the computeDistanceBetween, the results still differ for ~150 meters.
But, assuming that computeDistanceBetween respects the radius parameter, I assume Google relies on Haversine too, like turf does...
Both functions actually return the same values, when used properly!
Apparently, turfjs - since it is based on GeoJSON - uses LngLat formation instead of LatLng. Switching them around in turf.point definitions resolves the question and fixes all the related stuff I had.
For reference: https://macwright.org/lonlat/
A frustrating inconsistency in geospatial (mapping) software is coordinate order. Coordinates are often represented as arrays, like [-87.73, 41.83], instead of objects, like { lng: -87.73, lat: 41.83 }. This leaves it up to the developer to determine whether -87.73 is the longitude or latitude. One choice places a point on Chicago, and the other a location deep in Antarctica.
There's some consensus growing around longitude, latitude order for geospatial formats, but still chaos for libraries and software. It's up to the developer to be aware of this issue and read the requisite documentation, and flip coordinates if necessary to translate between different systems.

isLocationOnEdge tolerance calculation in terms of km

I am using google map map API
isLocationOnEdge
var isLocationNear = google.maps.geometry.poly.isLocationOnEdge(latlng, new google.maps.Polyline({
path: google.maps.geometry.encoding.decodePath(result.routes[0].overview_polyline)
}), .00001);
I dnt understand how tolerance is related to km
isLocationOnEdge(point:LatLng, poly:Polygon|Polyline, tolerance?:number)
Let sat i want to detect if a user is within 100m for any polyline drawn on map. How to fix this.
From one of the comments in this post:
tolerance, it is based on the decimal place accuracy desired in terms of latitude and longitude.
Example if say (33.00276, -96.6824) is on the polyline, if the tolerance is 0.00001 then if you change the point to (33.00278, -96.6824) then the point will ont be on the polyline.
So, you can probably use 0.001 as the tolerance value, if you want to find detect a location within about 100m for polyline.
For example, if your location is (1.001, 12), one of the points in polyline is(1, 12), the distance between your location and the polyline will be about 111.319 meters. The tolerance between (1.001, 12) and (1, 12) is 0.001, so the isLocationOnEdge() will return true.
If your location is (1.002, 12), distance to (1, 12), will be about 222.638 meters. The tolerance between them is 0.002, so if you use number 0.001 as the tolerance value for isLocaitonOnEdge(), it will return false.
You can see the sample code from this JSFiddle: https://jsfiddle.net/j7cco3b0/1/
You can also create a custom function to validate in meters for a better precision.
var isLocationOnEdge=function(location,polyline,toleranceInMeters) {
for(var leg of polyline.getPath().b) {
if(google.maps.geometry.spherical.computeDistanceBetween(location,leg) <= toleranceInMeters){
return true;
}
}
return false;
};
The package for isLocationOnEdge which I found is as given below -
com.google.maps.android.PolyUtil.isLocationOnEdge()
It worked for me.

Random GPS coordinates in a non rectangular space

I am working on an user interface that shows many pins on a map.
During the development I am randomly generating 1500 map pins just to be placed on the map to test look/feel/performance etc. issues.
The code which does that looks like this:
for (var i = 0; i <= 1500; i += 1) {
$scope.mapPins.push({
latitude: (Math.random() * 2) + 51,
longitude: (Math.random() * 4) + 3,
icon: themeImages[Math.floor(Math.random() * themeImages.length)],
title: 'Sample title',
infoContent: 'Sample content'
});
}
Naturally the area of the pins covered is a rectangle for latitudes 51-53 and longitudes 3-7. For those who are wondering where it is, it is the area roughly around Netherlands.
Now, there's a little problem that the Netherlands is not a rectangular area and a lot of these coordinates fall over the sea and I would like my coordinates to be only on the land.
Is there a witty mathematical way how I can pool coordinates from a non-rectangular area?
Of course I could make a google.maps polygon object that covers a nonrectangular shape and then via google api test every random generated pin whether it falls within the bounds of this shape etc, but that would be an overkill for UI design phase. Basically my question is whether there is a neat mathematical trick that would allow me to randomly generate coordinates from a non-rectangular space.
Leave your code as it is, the rectangle is the bounding box over your area of interest.
Then add a line
if (isPointInpolygon(polygon, longitudeOrX, latitudeOrY) {
// use this location
}
now you only need to search for a point in polygon function, which is easy to find.
you can directly use the coordinates in (long, lat) order, longitude is related to x coordinate, lat to y.
The polygon has to be filled with the coordinates of the country not insode the water.
If you have islands, then maybe you need multiple such polygons, then iterate over all.
Not to be a stickler but you're actually generating 1501 map pins :)
It is very unlikely that you'll find a simpler solution than using a simple pointinpolygon check.
Use the Google Maps Drawing library (https://developers.google.com/maps/documentation/javascript/drawing#using_the_library) to draw a polygon around the boundary of the Netherlands and save it however you want (e.g., in database, or just copy the string that defines the boundary's coordinates).
Then in your script above, define the google maps polygon (similar to what is done here in the official docs: https://developers.google.com/maps/documentation/javascript/shapes#polygons), then use the containsLocation method in the Google Maps Geometry library (https://developers.google.com/maps/documentation/javascript/examples/poly-containsLocation) to check if your random map pins lie within the boundaries of the Netherlands before adding them to the map.
For example:
var netherlandsCoords = [
// comma-separated list of coordinates defining the Netherlands boundary
];
var netherlandsBoundary = new google.maps.Polygon({
path: netherlandsCoords
});
for (var i = 0; i <= 1500; i += 1) {
var lat = (Math.random() * 2) + 51;
var lng = (Math.random() * 4) + 3;
var latlng = new google.maps.LatLng(lat, lng);
if (google.maps.geometry.poly.containsLocation(latlng, netherlandsBoundary)) {
$scope.mapPins.push({
latitude: lat,
longitude: lng,
icon: themeImages[Math.floor(Math.random() * themeImages.length)],
title: 'Sample title',
infoContent: 'Sample content'
});
}
}

Heat map from latitude & longitude

I want to generate heat map from a set of data which is latitude & longitude. I've 20,000+ latitude & longitudes in a text file.
Can any one tell me how to generate heat map?
I'll appreciate if some one can provide me free version of heat map.
Thanks!
There's an open source library called heatmap.js which might work for you. It's HTML5 based so won't work in older browsers though. They also have a GMaps Heatmap Overlay, so it's fairly plug and play.
Simpleheatmap.com will let you plot latitude & longitude coordinates on an interactive heatmap for free. No limit on the number of lat/lon pairs you can plot, though as of the time of this writing it's in beta so that might change. The site also has the ability to geocode addresses and other geographic data and plot them as well, but there are limits on how many geocoding attempts you can make.
Another useful website for heatmap is http://www.openheatmap.com
Also a blog discusses about heatmap: http://blog.smartbear.com/web-monitoring/the-heat-is-on-a-simple-guide-to-creating-heatmaps/
StringBuilder sb = new StringBuilder();
sb.Append("<script>");
sb.Append(" var latlng = new google.maps.LatLng(18.345, 79.497);");
sb.Append("var myOptions = { zoom: 7, center: latlng, mapTypeId: google.maps.MapTypeId.satellite };");
sb.Append("var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);");
sb.Append("var heatmap = new google.maps.visualization.HeatmapLayer({ data:[");
for (int i = 0; i < dreal.Rows.Count; i++)
{
string str = "new google.maps.LatLng(" + dreal.Rows[i][0].ToString() + "," + dreal.Rows[i][1].ToString() + ")";
if (i> 0)
{
sb.Append(",");
}
}
sb.Append("]");
sb.Append(", map: map });");
sb.Append("</script>");
Page.ClientScript.RegisterStartupScript(this.GetType(), "ArrayScript", sb.ToString());
Here I am generating javascript from backend and I am taking datatable values which are having two columns for longitude and latitude. and I am taking one of the datatable for initializing the map variable.