Tag Info

Hot answers tagged

21

This question turned out to be a bit trickier than I thought to get right. There are many implementations of the shortest distance itself, such as the Shapely provided distance (from GEOS). Few of the solutions provide the intersection point itself, however, but only the distance. My first attempt buffered the point by the distance between the point and ...


18

I investigated exactly this question 20 years ago when designing a desktop GIS. We needed to find point-to-point distances interactively; our target was to do the computations in less than 1/2 second for thousands of points. Testing (on a 25 MHz 486 PC!) showed that we could compute all the distances, exactly as you describe (with the simple obvious ...


8

a and b are alias table names to the same table. This is effectively a T1 CROSS JOIN T2 in DB-speak. This allows a self-join to say "how close one part is to another" in a single table. SELECT a.hgt AS a_hgt, b.hgt AS b_hgt, ST_Distance(a.the_geom, b.the_geom) AS distance_between_a_and_b FROM public."TestArea" AS a, public."TestArea" AS b WHERE ...


8

I have reproduced your example with shapefiles. You can use Shapely and Fiona to solve your problem. 1) Your problem (with a shapely Point): 2) starting with an arbitrary line (with an adequate length): from shapely.geometry import Point, LineString line = LineString([(point.x,point.y),(final_pt.x,final_pt.y)]) 3) using shapely.affinity.rotate to ...


7

It seems like if you have a lot more customers than you do stores, then it might be more efficient to create a layer of voronoi polygons for the stores, then do a spatial join of customers against the store polygons.


6

A PostGIS answer (for multilinestring, if linestring, remove st_geometryn function) select t2.gid as point_gid, t1.gid as line_gid, st_makeline(t2.geom,st_line_interpolate_point(st_geometryn(t1.geom,1),st_line_locate_point(st_geometryn(t1.geom,1),t2.geom))) as geom from your_line_layer t1, your_point_layer t2, ( select gid as point_gid, (select gid ...


6

There's a big "Nearest Neighbor" section on the BostonGIS page. EDIT: How about CREATE TABLE mytable_withinRange AS SELECT a.hgt AS a_hgt, b.hgt AS b_hgt FROM public."lon_TestArea" AS a, public."lon_TestArea" AS b WHERE ST_DWithin(a.the_geom, b.the_geom, 400) Concerning the CASE statement: SELECT a, CASE WHEN a=1 THEN 'one' WHEN ...


6

OK, I finally figure out a way to hack it that not only works around the dateline issue, but is also faster. CREATE OR REPLACE FUNCTION nearest_grid_point(point geography(Point)) RETURNS integer AS $BODY$ SELECT pointid FROM ( -- The normal case SELECT pointid, location FROM grid WHERE ST_DWithin($1::geometry, ...


5

Try running the sp_help_spatial_geography_index stored procedure to get details on how your spatial index is being used. You should be able to use something like: declare @ms_at geography = 'POINT (-95.66 30.04)' set @ms_at = @ms_at.STBuffer(1000).STAsText() exec sp_help_spatial_geography_index 'lidar', 'SPATIAL_lidar', 0, @ms_at; Post the results in ...


5

Quantum GIS has excellent support for PostGIS (which I guess you can use at home since it's free software), so if you are familiar with it, you could script this procedure using SQL with something like this: UPDATE poly_layer p SET neighbors_class = ( SELECT class FROM ( SELECT class, count(0) FROM poly_layer n WHERE ...


4

Discussions about some basic nearest neighbor solutions can be found here: http://www.bostongis.com/?content_name=postgis_nearest_neighbor#120 /Nicklas


4

likewise: select A.ID as CUST_ID, (select B.ID from B order by st_distance(A.geom,B.geom) limit 1) as STORE_ID from A


4

If you don't want to compute the distances between all the point combinations, you can use a spatial index on one of the table : SELECT A.id , B.myValue, MIN(Distance(A.Geometry, B.Geometry)) AS distance FROM tableOne AS A, tableTwo AS B WHERE A.ROWID IN ( SELECT ROWID FROM SpatialIndex WHERE f_table_name = 'A' AND search_frame = ...


4

With SRS/Map projections, it's always a trade off. There really isn't one that is a good fit for all places of the world. Might as well assume that the earth is a sphere. Instead of looking for a SRS that fits the whole world, I think you're better of looking for distance calculation algorithms. An example is the Great Circle Distance which is based on ...


4

Don't use the distance operation unless you actually need the distance. You can use the ST_DWithin to get geometries within a certain distance. Right now I don't have a PostGres database to test and give you a SQL query for your data, but have a look at the sample query given on the documentation page


3

Following R.K. suggestion, I have made 3 diferent rasters to test the NN resampling method in arcGIS and when passing from InRas resolution to a resolution that is 1/2 of it, the value of the new cell is allways given by the lower right input cell. On the left the different InRas files I've created (cell size1, 6x6), on the right the output of the ...


3

Hallo There is some things do consider to make things move faster, and some things that might be possible in the future. First, you mentioned that you are considering using a buffer to find polygons in some minimum range to avoid calculating all combinations. As discussed in another link from Boston gis the right way to do that in PostGIS is using ...


3

What you are looking for is Nearest Neighbor Query. Look at the following links, I think you will find what you are looking for. Nearest Neighbor Query Nearest Neighbors The nearest neighbor optimization in SQL Server Denali


3

You have to find the shortest pair in a search box, and if the box has nothing in it, expand it. It's not pretty but it works. There's example PL/PgSQL code here http://trac.osgeo.org/postgis/wiki/UsersWikiNearest


3

I have a solution. Not necessarily pretty but it works on my test dataset and is actually fairly easy. First up, this only works if your "houses" and "office" categorisation is numerical because you can't calculate a mode (what you want) from non-numerical data in ArcGIS. That should be easy enough to arrange so I'll leave it as an exercise for the reader. ...


3

Near by Group Something like this sounds like what you need. Conceptually, this question can be answered by the Near tool (what is the nearest feature?). However, the question also contains a constraint *(with the same attributes*?) that is not directly supported by the Near tool. To answer the full question additional ModelBuilder techniques must be ...


3

Working with the GeoNames.org database can be a bit difficult because of this inconsistency in the categories you described. I don't know where it comes from, but I guess it has to do with the different sources the names are from. In regions like Europe it is even harder to work with the GeoNames.org data, because of the different administration levels in ...


3

Just extract the upper triangular part of points_matrix and use the column sums as a criterion to remove the points: points_matrix <- gWithinDistance(points, dist = 20, byid = TRUE) points_matrix[lower.tri(points_matrix, diag=TRUE)] <- NA points_matrix # 1 2 3 4 5 # 1 NA FALSE FALSE FALSE FALSE # 2 NA NA FALSE FALSE FALSE # 3 NA ...


3

I think you want to exclude the intersection of the buffer in the where clause. WITH subq AS ( SELECT p.id, p.name, unnest(ARRAY(SELECT q.name FROM w_point q WHERE p.id != q.id AND NOT ST_Intersects(q.geom, ST_Buffer(p.geom, 0.1)) ORDER BY ST_Buffer(p.geom, 0.1) <#> q.geom LIMIT 5) ) as name FROM w_point p ) SELECT ...


2

See the comment below concerning how my answer should not be considered a reliable solution... I'll leave this original post here just so others can examine the problem. If I understand the question, this general procedure should work. To find the shortest path between a point (as defined by x,y or x,y,z) and a polyine (as defined by a connecting set of ...


2

What kind of use case do you have? Depending on your interests, it might be useful to look into "map matching algorithms". For example, there is a RoadMatcher project on OSM wiki: http://wiki.openstreetmap.org/wiki/Roadmatcher.


2

This is a bit old, but I was searching for solutions to this problem today (point --> line). The simplest solution I've come across for this related problem is: >>> from shapely.geometry import Point, LineString >>> line = LineString([(0, 0), (1, 1), (2, 2)]) >>> point = Point(0.3, 0.7) >>> point POINT (0.3000000000000000 ...


2

Another PostGIS answer If I understand you right the functionality you are asking for is built in PostGIS. To get a point projected on a line you can use ST_Closestpoint (on PostGIS 1.5) Some hints about how to use it you can read here: http://blog.jordogskog.no/2010/02/07/how-to-use-the-new-distance-related-functions-in-postgis-part1/ It is usable also ...


2

This uses Geography not Geometry (if data is Lat/Lng you data should be Geography Type not Geometry) "The SQL Server geography data type stores ellipsoidal (round-earth) data, such as GPS latitude and longitude coordinates." To Select the Top 5 Nearest Records from a lat/lng (-122.0 37.0) point you can use. SELECT TOP 5 ...



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