1

I am new to PostGIS and and PostgreSQL as well. I have been experimenting PostGIS for about a week now and I have seen that almost all blog posts or tutorials require having a shapefile to start querying against.

I can see that PostGIS is really powerful but little overwhelming for me as a beginner since I haven't understand it that much yet.

The main reason I am using PostGIS is to find users within radius and distance calculation for each point found within that radius.

3

The main reason I am using postgis is to find users within radius and distance calculation for each point found within that radius.

You don't need a shapefile if you understand ST_MakePoint and you can work with test data...

CREATE TABLE points(geom)
AS VALUES
  ( ST_MakePoint(0,0) ),
  ( ST_MakePoint(1,1) ),
  ( ST_MakePoint(1,0) ),
  ( ST_MakePoint(0,1) ),
  ( ST_MakePoint(2,2) ),
  ( ST_MakePoint(5,5) ),
  ( ST_MakePoint(10,10) ),
  ( ST_MakePoint(20,20) );

-- Shows the results as WKT (text)
SELECT ST_AsText(geom) FROM points;

-- Basic distance calculation between two points.
SELECT ST_Distance( ST_MakePoint(0,0), ST_MakePoint(2,2) );
   st_distance    
------------------
 2.82842712474619
(1 row)

-- Find all points within a distance
SELECT ST_AsText(geom)
FROM points
WHERE ST_DWithin( ST_MakePoint(0,0), geom, 2.82842712474619 );
 st_astext  
------------
 POINT(0 0)
 POINT(1 1)
 POINT(1 0)
 POINT(0 1)
(4 rows)
  • 3
    Exactly. Shape files have very little to do with Postgis, thankfully. We are free from the chronic restrictions (2gb dbf) and the inability to mix spatial types in a single shape file, not to mention the horrors of self-intersection and all the other things that ESRI allow/don't allow. So, I don't know what tutorials you have been reading, but, you sure as hell don't need shp files to start with Postgis -- in fact, I would say, it is a positive disadvantage. shp has become a standard, but it is not a very good one. GeoJSON is your friend :-) – John Powell Sep 1 '17 at 16:03
  • 2
    So, to answer you question, as Evan has done, the minimum requirements to perform a nearest geometry query would be two geometries, though the answer would be kind of obvious and boring. – John Powell Sep 1 '17 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.