I want to be able to do the following:
Select a Polygon and a point and see if the point lies within the polygon...I thought I could do this with MySQL but after a whole day of research it is simply not possible.
I have seen I need to use postgres and postgis, I have never used postgres before.
I have managed to install postgres and postpgadmin and it looks like I have created a database and got it up and running. Now I apparently need to add postgis to the database in order to use the functions? arent they just part of the postgres library? and why are people saying I need to add tables to the database to use the functions?
How do I add postgis to my database?
Can anyone give me any simple clear examples of a query to see if a point is in a polygon?
For purely geometrical queries you won't need postgis. Postgis is required when you want to mess with geographical data.
For an example of checking if a point is inside a polygon, this query should make it clear to you:
postgres=# select '((0,0), (1,1), (1,0))'::polygon #> '(.5, .5)'::point;
This will print true, meaning that the triangle formed by the points (0,0), (1,1) and (1,0) contains the point (.5, .5).
For more info check: http://www.postgresql.org/docs/9.0/interactive/datatype-geometric.html and http://www.postgresql.org/docs/9.0/interactive/functions-geometry.html
PostGIS is the spatial extension for the PostgreSQL database, and as is the case with many general-purpose databases, spatial functions have to be installed on top of a regular install.
The PostGIS website is informative, with nice documentation so head over there and read everything you need to know about obtaining and installing PostGIS.
Once installed and tested you'll need to spatially enable your database and then you're all set. If you have a dataset, of course.
Related
Question to experienced PostGIS users.
I am using official postgis/postgis:14-master image to run Postgres with PostGIS (gql API with ent&gqlgen in Go).
I am a bit surprised that with fresh db I get 8500 rows in "spatial_ref_sys" table. Seems like a lot (I read why it is needed in Postgis docs https://postgis.net/docs/manual-1.4/ch04.html#spatial_ref_sys)
So please tell me if is it normal or should I start looking into my Schema/edges.
Over the last few months, I've been using the openstreetmap-tile-server on GitHub (link here) to render OSM tiles from a Docker container. The tile server uses a PostgreSQL database to store its data. From doing more research into creating my own OSM tiles and my own tile server, a lot of tutorials mention using a PostgreSQL database.
Why is this? Why not use an SQL database such as MySQL instead? What can be gained / is gained from using PostgreSQL rather than a different SQL database for a dataset such as the openstreetmap data?
EDIT: Edited question, to indicate that I'm comparing Postgres to other SQL databases.
Originally MySQL was actually used for the main internal OSM database that stores actual OSM data and is queried and modified via the OSM API. For tile rendering and other purposes the internal raw format is never used though, instead OSM data exported as compressed XML or in more compact binary PBF format is imported into a database schema more suitable for further processing.
Typically this is done with either the "imposm" or the "osm2pgsql" tool, with the PostgreSQL/PostGIS combination as the RDBMS of choice, as it provides the most powerful GIS feature set, at least in the free & open source world.
The main OSM database is an exception as any queries on it are always retrieving data for a rectangular area only, and so GIS extensions are actually not needed, having the coordinates stored as simple numeric data is sufficient in this case. Eventually it was decided to switch that to PostgreSQL, too, to reduce the number of different components to maintain in the openstreetmap.org site setup.
In theory you could also use other RDBMS with GIS support, too, e.g. the SpatiaLite variant of SQLite, or MariaDB/MySQL, but compared to PostgreSQL/PostGIS setup they have their disadvantages:
E.g. SpatiaLite is only good as long as there's only one thread accessing the data, with concurrent access it doesn't scale well at all.
And MariaDB and MySQL only really implement more or less the bare minimum of the OpenGIS SQL specs, end even that only really materialized over the last years. Feature wise both are still more than a decade behind PostGIS at least.
Disclaimer: even I, although working for MariaDB Corp, and having worked for MySQL AB before, in total for over a decade, have always recommended to use PostGIS over MariaDB or MySQL for GIS applications unless someone was bound to MariaDB or MySQL for other reasons already.
I want to manage our spatial data in a database, and I learned Postgres and postGIS are good. I want to be able manage and also visualize the data in Google earth. I don't know where to start from. Is there any help ?
Yes PostGIS extension is used on Postgres to store and manage spatial data. You can use Postgres to store your spatial data. In order to use, postgres table in google earth you need to convert the table columns into kml/kmz.
For that you could use GDAL OGR command line tool. Which convert table into KML with command somthingh like below
ogr2ogr -f "kml" file_name.kml PG:"host=myhost user=myloginname \
dbname=mydbname password=mypassword" "myschema.table_name" \
-s_srs EPSG:<myEPSGcode> -t_srs EPSG:4326
EPSG is the coordinate reference system and other parameters are postgres credentials.
You need to explore it a little bit.
I'm developing the application about LBS with PostGIS.
I figured out the graph database has also shortest path algorithm.
Then I found the AgensGraph (GDB).
It looks possible because AgensGraph incubates the PostgreSQL. But when I install PostGIS additionally, I don't know what happens.
So can I use Lat/Long data and advanced shortest path algorithm in AgensGraph?
I have imported some osm map data into my PostGIS database using osm2pgsql.
These are my tables:
What is the best way to find a route between 2 points in my PostGIS tables?
Thanks
To do route-finding in postGIS you need to download, install, and enable the pgrouting extension.
Once you have a pgrouting enabled extension, then you need to create your graph topology using the pgr_createTopology function, after which you can use route finding algorithms like pgr_bdDijkstra.
See this pgrouting Getting Started guide, as well as the Routing Topology page for a bit more context.