I have a LineString geometry feature with weight in GeoJSON. Now I want to determine coordinates of 4 vertices of that rectangle. I know how to calculate on plane geometry by using line equation. But on geographic geometry, I'm new. I already read how to calculate one unit of latitude and longitude decimal degree as well as metres per pixel but I'm still confused how to add them to a given point to calculate wanted points. My problem is like this:
Given:
Broadth of rectangle
Coordinates of two points making the midline,
distance between these two points are equal to the width
Result: Coordinates of 4 vertices of rectangle
For example: Two point of LineString
A (10.767008,106.665884)
B (10.767715,106.667151)
Weight of LineString is 6 pixels at zoom level 18
I can calculate width of rectangle (distance between these two points), broadth of rectangle (number of metres per pixel, then multiply). How can I use them to calculate 4 vertices' coordinates of this rectangle?
All of my calculated cases are on small scale (part of one street of a city) so I think altitude can be excluded
It sounds like you want to get the "extent" of your linestring (a.k.a. the "bounding box" of your linestring). You can use turf.js' turf-extent function to get the extent of your GeoJSON linestring. That extent will be the rectangle you're looking for, as a GeoJSON polygon. You can then use other turf.js functions on that polygon to get the width, length, area, etc
Related
I have latitude and longitude coordinates.
-76.054657667, 36.818969167
Is there a simple function that will translate these to a fall into the center of a hexagon (in lat/long coordinates) of whatever size within a tesselating hexagon map (units can be arbitrary, say meters if you have to)?
I understand it can ambiguous because in Uber h3 or the d3 hex model whatever, there can be variance in where one hexagon starts and ends depending on your global map. I'm looking for a vastly simplified model here.
For instance, for basic square coordinates, a simple rounding function could work on both long and lat. If you round longitude and latitude to 2 decimal places for instance, you can 'bin' them into squares of a constant size.
I'm trying to simply bin them into hexagonal shapes, but using a a vastly simplified function for now.
Perhaps this sort of simplification is not possible, but curious. Thanks!
I am creating list of circles on my map using a loop. The circle radius may differ for each loop.
The logic should not overlap two circles. For this I need the following :-
Start with lat lng (circle center) and draw a circle.
Move radius*2 kilometer ahead and get the center point for second circle and so on.
Problem :
I am facing problem in the second step given above. How should I calculate the next point(Circle center) in row ? The input that I have is center point of first circle and radius.
Any suggestions?
The approximate conversions are:
Latitude: 1 deg = 110.574 km
Longitude: 1 deg = 111.320*cos(latitude) km
This doesn't fully correct for the Earth's polar flattening -- for that you'd probably want a more complicated formula using the WGS84 reference ellipsoid (the model used for GPS). But the error is probably negligible for your purposes.
Source: http://en.wikipedia.org/wiki/Latitude
So you can calculate the distance you need to move on the map and the latitude, Longitude for the next point on the map.
However there is a library (I have never used it, nut hope it helps)
http://www.jstott.me.uk/jcoord/
I use ol3 as a map service.
I have made a linestring with two points with coordinates : [[0,0],[0,1000]] and calculated the distance using the vincenty formula. This resulted in 1000 meter, what is accurate.
But when i made another linestring for example [[4052627,3971934],[4052627,3972934]] vincenty distance was around 850 meters.
I dont know what i forgot here. Any way to correct that? I want to calculate epgs:3857 meters (units) for a given real distance.
You can use ol.sphere.haversineDistance:
var c1 = [4052627, 3971934];
var c2 = [4052627,3972934];
var wgs84Sphere = new ol.Sphere(6378137);
var length = wgs84Sphere.haversineDistance(
ol.proj.transform(c1, 'EPSG:3857', 'EPSG:4326'),
ol.proj.transform(c2, 'EPSG:3857', 'EPSG:4326'));
// 833.12 m
Distances are tricky. The fact that the map units of a coordinate system are in meters (as epsg:3857) doesn't mean that you can measure distances in meters directly. See https://en.wikipedia.org/wiki/List_of_map_projections, and look how many of those have the "equidistant" property.
I suggest you use turf.js to calculate accurate geodetic distances: http://turfjs.org/static/docs/module-turf_distance.html
After alot of search I've found this PDF document:
Web Mercator:
Non-Conformal, Non-Mercator
There is something called Point Scale Factor - according to the way web Mercator is projected - which has tow values, not one like normal Mercator , North/South Scale Factor and East/West Scale Factor.
in my program I've ignored the East/West Scale Factors because it's to much small.
Once I've calculated the scale factor the real distance is almost equal to scale_factor * epgs_3857_distence
My map uses EPSG:900013 projection. As a result I get values in meters in the range of -20037508.342789244 to 20037508.342789244 when getting my mouse position.
I used the .transform() method of the LonLat class, using EPSG:900913 as the source projection, and (without thinking) used EPSG:4329 as the destination projection.
My question is, why is the EPSG:4329 giving me ranges from -180, 180, -80.05, 85.05 (which i wanted) instead of -180, 180, -90, 90 (which it should have given me, since those are the correct bounds http://spatialreference.org/ref/epsg/wgs-84/)?
I'm relatively sure your source projection (900913) is setting those constraints, so that when you move your mouse, you're limited to travelling so many meters away from 0,0, which corresponds to the 85.05 and -80.05 in your transformations.
Said differently, EPSG 900913 doesn't cover the complete globe. So when you move your mouse to the furthest north/south, respectively, it would transform not to +/- 90, but to 85.05 and -80.05, as you've discovered.
If you go and check this page in the OpenLayers docs, they explain it as follows:
Specifically, most spherical mercator maps use an extent of the world
from -180 to 180 longitude, and from -85.0511 to 85.0511 latitude.
Because the mercator projection stretches to infinity as you approach
the poles, a cutoff in the north-south direction is required, and this
particular cutoff results in a perfect square of projected meters.
I can do this to convert a lat/lng to pixel coordinates in Google maps:
var xy = map.getProjection().fromLatLngToDivPixel(new google.maps.LatLng(lat, lng));
Now I'm wondering, how do I get a distance in pixels from that point? Say I want to draw a circle with a radius of 5 miles around that. How do I do that?
In v3 there is the circle object
The best way to draw a circle around a given point is to draw a GPolygon with many points, simulating a circle.
You can find a good example of this here. Look for the drawCircle function in the source (you will need to download the attached circle.html to check it out.