Tag Info

Hot answers tagged

15

I would recommend checking out: Spherical: http://www.movable-type.co.uk/scripts/latlong.html Great-Circle: http://www.movable-type.co.uk/scripts/gis-faq-5.1.html


14

This is terrible code for general-purpose use because it can give erroneous results or even fail altogether for short distances. Use the Haversine Formula instead. (The formula on which your code is based converts two points on the sphere (not an ellipse) into their 3D Cartesian coordinates (xa,ya,za) and (xb,yb,zb) on the unit sphere and forms their dot ...


8

Although geodesics do look a little like sine waves in some projections, the formula is incorrect. Here is one geodesic in an Equirectangular projection. Clearly it is not a sine wave: (The background image is taken from http://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Equirectangular-projection.jpg/800px-Equirectangular-projection.jpg.) ...


6

So you know your two latitudes and longitudes, lets say You can calculate the cartesian co-ordinates for each: xa = (Cos(thisLat)) * (Cos(thisLong)); ya = (Cos(thisLat)) * (Sin(thisLong)); za = (Sin(thisLat)); xb = (Cos(otherLat)) * (Cos(otherLong)); yb = (Cos(otherLat)) * (Sin(otherLong)); zb = (Sin(otherLat)); And then calculate the great circle ...


6

Sadly there isn't a geographic version of ST_ClosestPoint, so you will have to write your own function. There are two ways of calculating the nearest point of a great circle: spherical trigonometry, or 3D vector algebra. Luckily for you I have just written such a function for the latter method; I've not attempted the former because my spherical trig is ...


5

It seems to be a straight line in whatever projection system pertains when it is created. After that, it is recalculated in each new projection, and the software trys to make it 'stratght'. this is quite noticeable near the poles: a square drawn round the pole in a polar azimuthal projection will invariably turn into a circle (that is, the formerly stratight ...


5

Take a look at this site, http://www.movable-type.co.uk/scripts/latlong.html If you implement it and you get the wrong answers you probably have the wrong units. I think for that site most operations are done in radians instead of decimal degrees.


4

The answers provided by others are a little more elegant, but here's an ultrasimple, somewhat unpythonic, bit of Python that provides the basics. The function takes two coordinate pairs and a user-specified number of segments. It yields a set of intermediate points along a great circle path. Output: text ready to write as KML. Caveats: The code does not ...


4

While an algebraic solution is possible if one assumes the earth is a sphere, we can still handle an ellipsoidal earth using Newton's method and a Esri's projection engine. The projection engine is a c style dll (pe.dll) and is bundled with the freely downloadable ArcGIS Explorer. I think the question could be rephrased as ... A plane is flying from ...


3

One-liner, assuming the POI points are stored in a "geography" column, you supply the ids of the two points and the search radius in meters: WITH line AS ( SELECT ST_MakeLine(p.geog::geometry, q.geog::geometry)::geography AS geog FROM pois p, pois q WHERE p.id = :id1 and q.id = :id2 ) SELECT p.name, p.id FROM pois p JOIN line ON ST_DWithin(p.geog, ...


3

This is the PL/pgSQL version of MerseyViking's code. It also uses PostGIS geography Point and LineString types rather than a custom type to represent coordinates. CREATE OR REPLACE FUNCTION _point_to_cartesian(point geometry(Point), radius float, OUT x float, OUT y float, OUT z float) RETURNS RECORD AS $BODY$ DECLARE lon float; lat float; BEGIN ...


3

GeographicLib has a python interface http://geographiclib.sourceforge.net/html/other.html#python This can computer geodesics on an ellipsoid (set flattening to zero to get great circles) and can generate intermediate points on a geodesic (see the "Line" commands in the sample). Here's how to print out intermediate points on the geodesic line from JFK to ...


2

Here are some links that might help: http://www.koders.com/python/fid0A930D7924AE856342437CA1F5A9A3EC0CAEACE2.aspx http://code.activestate.com/recipes/393241-calculating-the-distance-between-zip-codes/


2

You could use a similar hack to the ST_Intersection for geography. Would look like this: CREATE OR REPLACE FUNCTION st_closestpoint(geography, geography) RETURNS geography AS $$SELECT geography(ST_Transform(ST_ClosestPoint(ST_Transform(geometry($1), _ST_BestSRID($1,$2)),ST_Transform(geometry($2), _ST_BestSRID($1,$2)) ),4326)) $$ ...


2

How about transforming your starting coordinate to one on an azimuthal projection centered at the starting point. Then move at the appropriate azimuth for the desired distance, and transform back to geographic coordinates? A few resources: Wikipedia on Azimuthal Equidistant Projections Proj Syntax for the same


1

Python: # From: http://www.movable-type.co.uk/scripts/latlong.html def distance(lon1, lat1, lon2, lat2): # http://code.activestate.com/recipes/576779-calculating-distance-between-two-geographic-points/ # http://en.wikipedia.org/wiki/Haversine_formula dlat = lat2 - lat1 dlon = lon2 - lon1 q = sin(dlat/2)**2 + (cos(lat1) * cos(lat2) * ...


1

There is no information on this in the shapefile specification. How to connect two vertices is strictly up to the software displaying or otherwise processing the shapefile. You could add information into an attribute field which could then be used by the software, but it would affect the entire feature. Esri has been working a bit on this, so there are ...


1

Here is a full algebraic solution for two arbitrary small circles, using Cartesian coordinates to simplify the maths. It's assumed the earth is a spherical, but that's fine for my purposes.



Only top voted, non community-wiki answers of a minimum length are eligible