GPS coordinates to pixel - java

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.

Related

How to get the position of the point in the view after rotate?

I have a View that has the moving, rotating and scaling capability, I have all the four-corner positions and I want to get the position of some imaginary points in it so that can be constant with scaling and moving
Please take a look at the picture below to understand it well.
Edit:
After re-reading I see that question is not clear
If you need to transform points when you know initial and ending corner coordinates, then calculate matrix of affine transform using three pairs of coordinates as described here and apply that matrix to all needed points.
But you also mentioned points .. that can be constant - as far as I understand - point that preserve their coordinates after transform.
You should know matrix of affine transform that is applied to your coordinates.
For this matrix calculate eigenvalues and corresponding eigenvectors (there are up to three of them)
If some eigenvalue is 1, then static point does exist, and corresponding eigenvector being normalized to the form (x,y,1) represents coordinates of your static point.

Draw Marker of Store along the route between two point

I have to show stores on Google map between two Locations.
Suppose I have 5000 stores all over the country. But how could I only draw store marker between my routes. I mean show stores coming in my way on Map. As Latitude longitude don't change gradually while moving b/w two points. How could I query like
Read all store which lie on the given route between two points.
As route consist of polyLines I think I should create circular area between each polyline and If any store lat lng lie in that area draw it on Map. But when I have a big polyline it's circle will be bigger and I don't want to show store that are far away from my routes.
I need a better approach to show my store on map in my route. And I need it before moving.
You don't need to create a circular region or a polygon. Consider the documentation of Polyline. I found a very helpful method here
isLocationOnPath(LatLng point, java.util.List<LatLng> polyline, boolean geodesic, double tolerance)
Computes whether the given point lies on or near a polyline, within a specified tolerance in meters.
For further detail consider this
http://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/PolyUtil.html

Inverse/Perspective transformation applied to a point

I have a problem in my application.
I would like to take a picture then draw a mask on it, knowing tilt and inclination angle. In testing phase, I chose to work on a simple lens checker where I draw a mask with known real coordinates and I'm supposed to find same
coordinates with code.
When tilt = 0 and inclinationAnle = 0 (default case) all works fine, the same when
tilt !=0.
The images are taken with same distance between camera lens and the lens checker's center.
This is the reference example:
Now with just applying a rotation and drawing the same mask, we get this:
Applying a simple rotation with -tilt angle get us the same eight points' coordinates as in the default case and it works fine.
The problem is when I change inclination angle like this:
I understood that it's a perspective transformation (or inverse) but I don't want to transform the image itself, I want from eight points' coordinates to retrieve the default case' coordinates. Like in a real case, I don't know the default case' coordinates, just the inclination angle. So a user takes a picture with the mask and i must retrieve mask coordinates as if the picture was taken without inclination or tilt. Here the points are in 2D (X,Y).
I'm sorry if this is duplicated somewhere, but I've looked everywhere, used OpenCV but couldn't get what I need.
Any needed infos will be provided and thanks for any help .

Convert Latitude and Longitude values to a custom sized grid

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.

How to use Javas Polygon class with lat,longs

I have two geo-spatial simple convex polygon areas, in latitudes and longitudes (decimal degrees) that I want to compute using Javas Polygon class. I basically want to see if these two lat,long polygons intersect, and to calculate the areas (in sq meters) of both.
Now java.awt.Polygon class only uses x,y co-ordinate system, but I need to use lats,longs.
How can I do this, and/or is there any other classes/libraries available?
Why not use Polygon class multiplying coordinates for 10^n making them integers? Polygon accepts arrays of int as points.
Just an Idea
All you need to do is convert from spherical to rectangular coordinates if you think that really matters.
I'm not sure that it does, because the java.awt.Polygon is merely a data structure holding for pairs of values. If you read the javadocs, they say
The Polygon class encapsulates a description of a closed, two-dimensional region within a coordinate space. This region is bounded by an arbitrary number of line segments, each of which is one side of the polygon. Internally, a polygon comprises of a list of (x,y) coordinate pairs, where each pair defines a vertex of the polygon, and two successive pairs are the endpoints of a line that is a side of the polygon. The first and final pairs of (x,y) points are joined by a line segment that closes the polygon.
They happen to label those points as x and y, which makes all of us think rectangular coordinates, but they need not be from your point of view. A bug on the service of your sphere would view it as a 2D space. Your radius is large and constant. You just can't count on using any of Polygon's methods (e.g., contains(), getBounds2D(), etc.)
In this case, the important thing is your area calculation. You can use a Polygon for your area calculation, storing lats and longs, as long as you view Polygon as a data structure.
You might also thing of abandoning this idea and writing your own. It's not too hard to create your own Point and Polygon for spherical coordinates and doing it all with that coordinate system in mind from the start. Better abstraction, less guessing for clients. Your attempt to reuse java.awt.Polygon is admirable, but not necessary.
You can perform the area calculation easily by converting it to a contour integral and using Gaussian quadrature to integrate along each straight line boundary segment. You can even include the curvature of each segment at each integration point, since you know the formula.
Going off my intuition here.
If the polygons are small in ratio to the size of the planet you can treat them as flat polygons. The steps involved would be converting the lat/long into absolute x/y/z, taking any three of the points and finding the normal of the plane the polygons lie on and then using this to project the points into two dimensions. Once you have the 2D points it's easy to calculate the area or if they intersect.
Probably not the best answer but hopefully it will motivate some people to make better ones because it's a good question.
Maybe you could use GeoTools for this. It allows you to create Geometry objects, and check wether they intersect (see: Geometry Relationships)
Here is a solution that works like a charm:
Class PolygonArea from net.sf.geographiclib
Refer link below with sample code:
https://geographiclib.sourceforge.io/html/java/net/sf/geographiclib/PolygonArea.html
gradle dependency:
compile group: 'net.sf.geographiclib', name: 'GeographicLib-Java', version: '1.42'

Categories