I am developing one application in which i have draw the polygon on map and map that I have used is not google,Its Mapsforge opensource offline map library.i have easily draw polygon on map by converting geopoint into pixcel point.but here i want to find are of that irregular polygon,and for that i have make lots of try but its getting me unsuccess..
I have tried with calculate area with basic Math but its not working in this case be case pixcel are change accodingly while change zoom level.
Here is Math logic :
Math calculation
for(int miAreainc = 0;miAreainc < x.length-1; miAreainc++)
{
sumX += x[miAreainc] * y[miAreainc + 1];
sumY += y[miAreainc] * x[miAreainc + 1];
}
int unit = ((sumX - (sumY)) / 2);
AppLog.showLogE(TAG,"UNIT >> " + unit);
I found that funcation stay at server side which get area from geopoint array,but here I want to make it offline.
I have tried so far but not getting any clue or result ..
Please help me out this..
Thanks
Note: I don't really know how stupid my answer is. So please let me know if it doesn't make sense and I'll delete it.
Since the map is not in Cartesian Coordinate System, your calculation will not yield accurate result. You need Spherical Trigonometry for Spherical Polygon which is not trivial.
There is a good discussion at Calculating area enclosed by arbitrary polygon on Earth's surface. Take a look.
But apart from all of these, I have found Projection.java in mapsforge which has a method to find the absolute pixel coordinates on the world map from GeoPoint at a specific zoom level:
Translates the given {#link GeoPoint} to absolute pixel coordinates on
the world map.
Point toPoint(GeoPoint in, Point out, byte zoomLevel);
I'm not really knowledgeable, but I think it will give you the absolute coordinate of GeoPoint on a projected map so you can use Cartesian calculation.
for area calculation you Need to transform lat, lon to cartesian coordinates with Unit Meters. (Not Pixels) Look into transform Moduls
Related
I have a position given in decimal degrees (x.xxxxxxxx and y.yyyyyyyy). I need to draw a rectangle around it. The center of the rectangle matches the position. The dimensions of the rectangle is given in meters and it has a rotation ranging from 0-360 degrees.
Question
How can I calculate the four corners of the rectangle and return the result as four decimal degree values? Like arrayOf<LatLon> getRectangle(LatLon position, int rectWidthCm, int rectLengthCm, double rectRotation).
Example
I have a position given in LatLon format with two two values: latitude and longitude. We will assume this location is precise.
The main task is to draw a rectangle based on this position in a Google Maps chart. The rectangle can have any dimentions but let's use these in this example: Width = 0.9 meter and Length = 1.2 meters. Any heading may also be given so lets use this heading: 45. 0 Is north and going clockwise round (east = 90, south = 180 and west = 270). When the rectangle is pointing north it has the length in the north/south direction. Finally, the rectangle center should be equal to the given position.
Note: The project setup is an Android application with Kotlin support and a google maps chart. I am interested in a modern approach to this problem. Regarding precision loss it should at most be within centimeters.
I understand that you are looking for a function geo_rect(x,y,w,h,a) with the following parameters
x is the longitude according to WGS84
y is the latitude
w is the width of the rectangle in meters
h is the height of the rectangle in meters
a is the angle to which the rectangle is turned from w being horizontal (meaning pointing exactly West to East). I suggest to allow values ranging within the open interval (-90°,90°) as this makes the math either to understand.
Your function getRectangle(LatLon position, int rectWidthCm, int rectLengthCm, double rectRotation) deliver all the required information, you need a small wrapper function which determines w, h, and a from rectWidthCm, rectLengthCm and rectRotation, with the latter being within [0°,360°).
The function geo_rect() will return an arrayOf<LatLon> of length four, namely the coordinates of all four corners, starting on the top left and then going clockwise. We will refer to the points as P_NE,P_NW,P_SE, and P_SW respectively.
Assumptions
In order to keep things mathematically feasible, we make some assumptions
We assume that we can use as approximation that the rectangle is a plane, which is okay if w ~ h << r with r = 6378 km being the radius of the Earth.
We further assume that the Earth is a ideal sphere rather than an ellipsoid or even more bumpy. For an accessible article on that issue, see e.g. Zachary C. Eilon's blog
Basic structure of the algorithm
The algorithm could be structured as follows:
Determine the distance d from (x,y) to all four end points. Because of our first assumption we can use simple Euclidian geometry rather than intricate Spherical geometry. Pythagoras holds: d^2 = (w/2)^2 + (h/2)^2.
We also need the four bearings, e.g. b_NW for the angle between the vector pointing to the North Pole and the vector pointing from (x,y) to point P_NW.
Given the information (x,y,d,b_NW, b_NE, b_SW, b_SE) from the previous steps, we can now follow Get lat/long given current point, distance and bearing to calculate the position of all four points. This is the mathematically hard part where I suggest to use a well-established and tested library for.
Last but not least, let us double-check whether the calculation went well by evaluating Great circle distances between some or all pairs of points. For instance d(P_NE,P_NW) should approximately be w, d(P_NW,P_SW) should approximately be h. Don't be surprised if there is actually a difference - this errors are due the assumptions we made. Normal GPS under usual conditions will anyhow not allow you to determine your position up to the centimeter, you will need DPGS for that.
Further reading
At https://www.movable-type.co.uk/scripts/latlong-vectors.html you can experiment online to determine a destination point along a great-circle given the distance and bearing from a start point (in our case: the center of the rectangle).
Old, but amazingly documented and well tested tool kit for geo-applications in general are the https://www.generic-mapping-tools.org/ - you might want to look at the command gmtvector.
If you are looking for java implementations, I found e.g.
https://introcs.cs.princeton.edu/java/12types/GreatCircle.java.html on of many implementations for calculating great circle distances
Need a standalone Java library for performing spatial calculations on lat/lon data
Calculate point based on distance and direction
I've looked many places and haven't found any resources (that I understand) that explain how to turn the standard Midpoint circle algorithm (which uses octants to create the whole circle) into only considering a specific 'slice' of the circle. I'm using this to find the tiles within a line of sight radius.
the code I'm using is the basic Wikipedia code of how to implement the algorithm.
I'm using java inside "Processing" to prototype things out.
I'm trying to understand how this algorithm works so I can modify it, but I'm having trouble.
The midpoint algorithm or Bresenham algorithm can be extended with a condition if the point you are rasterizing falls into the range you have specified by the angles (points). To get the range you would have to find the starting and ending point on the circle. This can be easily accomplished with help of polar coordinates. If we have a circle with radius r, angle theta and center C(x0,y0) the point on the circle can be computed as pCircle(x,y) = (x0 + r * cos theta, y0 + r * sin theta). Note that the angle is in radians.
I am making a java program that classifies a set of lat/lng coordinates to a specific rectangle of a custom size, so in effect, map the surface of the earth into a custom grid and be able to identify what rectangle/ polygon a point lies in.
The way to do this I am looking into is by using a map projection (possibly Mercator).
For example, assuming I want to classify a long/lat into 'squares' of 100m x 100m,
44.727549, 10.419704 and 44.727572, 10.420460 would classify to area X
and
44.732496, 10.528092 and 44.732999, 10.529465 would classify to area Y as they are within 100m apart.
(this assumes they lie within the same boundary of course)
Im not too worried about distortion as I will not need to display the map, but I do need to be able to tell what polygon a set of coordinates belong to.
Is this possible? Any suggestions welcome. Thanks.
Edit
Omitting projection of the poles is also an acceptable loss
Here is my final solution (in PHP), creates a bin for every square 100m :
function get_static_pointer_table_id($lat, $lng)
{
$earth_circumference = 40000; // km
$lat_bin = round($lat / 0.0009);
$lng_length = $earth_circumference * cos(deg2rad($lat));
$number_of_bins_on_lng = $lng_length * 10;
$lng_bin = round($number_of_bins_on_lng * $lng / 360);
//the 'bin' unique identifier
return $lat_bin . "_" . $lng_bin;
}
If I understand correctly, you are looking for
a way to divide the surface of the earth into approximately 100m x 100m squares
a way to find the square in which a point lies
Question 1 is mission impossible with squares but much less so with polygons. A very simple way to create the polygons would to use the coordinates themselves. If each polygon is 0.0009° in latitude and longitude, you will have approximately square 100m x 100m grid on the equator, put the slices will become very thin close to the poles.
Question 2 depends on the approximation used to solve the challenge outlined above. If you use the very simple method above, then placing each coordinate into a bin is just a division by 0.0009 (and rounding down to the closest integer).
So, first you will have to decide what you can compromise. Is it important to have equal area in the polygons, equal longitudinal distance, equal latitude distance, etc.? Is it important to have four corners in the polygon? Is it important to have similar or almost similar polygons close to the poles and close to the equator? Once you know the limitations set by your application, choosing the projection becomes easier.
What you are trying to do here is a projection onto a flat surface of an ellipsoid. So as long as your points are close together, and, well, you don't mind getting the answer slightly wrong you can assume that your projection plane intersects in the centre of your collection of points, and, each degree of lat and lon are a constant number of metres. Then the problem is a simple planar calculation.
This is wrong, of course. I would actually recommend that you look into map projections, pick one that makes sense, and go for that. Remember that you can move the centre of the projection to the centre to your set of points which will reduce distortion.
I suspect that PROJ.4 might help you in terms of libraries. There also must be a good Java one but that is not my speciality.
Finally you can could assume that the earth is a sphere and do your calculations on the sphere. Or, if you really want to get it right you can pick a standard earth ellipsoid and do the calculations on that.
I need to create image (polygon) from GPS coordinates. I have coordinates like this:
(49.274633220,17.160206083),(49.276968797,17.162732143),(49.278188519,17.162391767),(49.279761626,17.161087954), ......
And I need to transform them to XY pixel points. Each pair of coordinates are vertex of created polygon.
File with all coordinates:
GPS.txt
and how the created polygon should look like:
Any idea how can I transform the coordinates? Thanks for all reply.
In all cases you need a transformation form lat,lon (spherical) to cartesian (x,y) coordinated.
If the polygon is not bigger than 100km you can use a simple Cyclindrical Equidistant Projection.
Otherwise, you may use a Mercator Projection. (Google Maps uses that too)
Are you sure the assignment says to create a graphic? Or is it just to read the text file and extract the pairs of coordinates? Because you can't create a graphic without defining a transformation. I would start by finding the max and min latitude and longitude values (making sure which is which!). Then just use a linear scale for the longitude so that your minimum longitude goes to px=0 and the maximum longitude goes to however wide you want your image to be. Then do the same for latitude - it'll look distorted but at least you'll see something to start with.
By the way, the graphic you pasted doesn't seem to correspond to the coordinates you gave. If it helps, yours look more like this red area.
I'm trying to obtain the camera rotation on various axis in OpenGL (but using Java, LWJGL, and jME specifically). The camera object allows me to get the direction as a Vector3f, but this doesn't seem to work to get the componentised rotation; each axis appears tied to another axis. I found that toAngleAxis with the angle component with offset was a quick hack, but doesn't work properly in most situations. I'm not so good at maths unfortunately, otherwise I may have been able to work out this problem :) Again, I just need the X, Y and Z axes componentised and in radians, from 0 radians to 2 PI radians.
Can anyone help?
Cheers and thanks in advance,
Chris
I'd recommend reading about Euler Angles, yaw/pitch/roll, and quaternion orientation. These topics will help you understand everything involved. If I understand correctly, you're trying to construct Euler angles from a specified orientation.
See this code for some algorithms for working with Euler angles. In particular, I believe what you want is the setDirection method.
This will give you a yaw and pitch from a directional vector. Note that you only need 2 rotations, though, since "roll" would require a rotation about the directional vector (or your direction specified as a single quaternion rotation).
Obtaining the rotation angels requires just transforming the view vector given in cartesian coordinates into spherical coordinates. You can find the formulas in wikipedia.
viewvector = <x, y, z>
r = sqrt(x² + y² + z²)
phi = arctan2(y, x)
theta = arccos(z / r)
Note that you can only obtain two rotation angels form the view vector. Obtaining the third rotation angle requires knowing the projection plane x or y axis.