PostGIS

Add geometry field to PostGIS with Rails

廉价感情. 提交于 2020-01-16 02:54:08
问题 I have a database with a table called addresses. I want to add a geometry field. I could do it in pgAdmin, but not sure how it would play with Rails. I think sql would be: ALTER TABLE addresses ADD geom geometry(Point,4326) Then I will want to run UPDATE addresses SET geom = ST_SetSRID(ST_MakePoint(longitude,latitude),4326); Can I do that in Rails or must I do it in pgAdmin (or psql)? Thanks. Newbie getting lost in the complications of mashing several applications. 回答1: Are you using this gem

How to convert point text to geometry

[亡魂溺海] 提交于 2020-01-15 12:18:22
问题 I have installed postgis in my DB. Now i have 1 regions in my DB like ((-79.4609576808001,43.9726680183837)) I want this region to convert to geometry type. I have searched on google and found that St_geomfromText will convert text to geometry type. my query is as follows: SELECT ST_GeomFromText(region,4326) from "erpAssets"; But it is giving error it is saying that no function matches for st_geomfromtext 回答1: You can also use ST_MakePoint which is probably cleaner as you don't have to

Postgres' CTE vs Subquery Performance difference. Why?

放肆的年华 提交于 2020-01-15 03:08:47
问题 I have two equivalent queries which extracts the average distance between buildings (table a) and the nearest highway (highways in table v) in a specific district (ace) and city (pro_com). This is the CTE version WITH subq AS ( SELECT a.n, a.geom as g1, unnest(ARRAY(SELECT v.geom as g2 FROM atlas_sezioni2 as v where v.code = '12230' and a.pro_com = v.pro_com and a.code <> v.code ORDER BY a.geom <-> v.geom LIMIT 15)) as g2 FROM atlas_sezioni2 a where a.pro_com = 15146 and a.ace = 1 and a.code

PostgreSQL: ST_GeomFromText(unknown) does not exist

淺唱寂寞╮ 提交于 2020-01-14 18:46:10
问题 Here is the problem, I just installed PostgreSQL right now and try to build a geoloc database. For this, i installed the PostGIS extension and PostGIS_Topology. In my pgAdmin UI, i can see my model, my schema is "Geo" and I can see below, in the functions list, the postGis functions that are available (about 1000, see screenshot) Problem is, when I try to insert a new record in the database, Example: INSERT INTO "Geo".points(point, lat, lng) VALUES (ST_GeomFromText('POINT(42.555 32.222)'),'42

PostgreSQL: ST_GeomFromText(unknown) does not exist

心已入冬 提交于 2020-01-14 18:45:09
问题 Here is the problem, I just installed PostgreSQL right now and try to build a geoloc database. For this, i installed the PostGIS extension and PostGIS_Topology. In my pgAdmin UI, i can see my model, my schema is "Geo" and I can see below, in the functions list, the postGis functions that are available (about 1000, see screenshot) Problem is, when I try to insert a new record in the database, Example: INSERT INTO "Geo".points(point, lat, lng) VALUES (ST_GeomFromText('POINT(42.555 32.222)'),'42

Dynamic UNION ALL query in Postgres

懵懂的女人 提交于 2020-01-13 06:11:35
问题 We are using a Postgres / PostGis connection to get data that is published via a geoserver. The Query looks like this at the moment: SELECT row_number() over (ORDER BY a.ogc_fid) AS qid, a.wkb_geometry AS geometry FROM ( SELECT * FROM test UNION ALL SELECT * FROM test1 UNION ALL SELECT * FROM test2 )a In our db only valid shapefiles will be imported each in a single table so it would make sense to make the UNION ALL part dynamic (loop over each table and make the UNION ALL statement). Is

Can PostGIS be used to create a grid map of a country?

僤鯓⒐⒋嵵緔 提交于 2020-01-12 09:39:38
问题 I'm trying to divide the map of an area into 1 km x 1 km square grids and ultimately, count and retrieve how many points (given their latitude and longitude values) fall into each square grid of this map. Can this operation be done in the PostGIS, if so, how can I do that? UPDATE: Mike Toews has a detailed answer here: https://gis.stackexchange.com/questions/16374/how-to-create-a-regular-polygon-grid-in-postgis 回答1: As mentioned in my comment make a regular grid. To make a 1 km grid for a

PostGIS - convert multipolygon to single polygon

假如想象 提交于 2020-01-11 22:49:01
问题 Is it possible to import a shape file containing multipolygons into single polygon in PostGIS? Whenever I try importing a shape file of a polygon, it is stored as a multipolygon (as opposed to a single polygon) in a geom column. Thus, I am unable to extract it as a single polygon value from the multipolygon. All helpful suggestions much appreciated 回答1: You can use ST_GeometryN together with ST_NumGeometries and the generate_series function to obtain what you need. Let's assume you have the

Query by coordinates takes too long - options to optimize?

时间秒杀一切 提交于 2020-01-11 07:05:15
问题 I have a table where I store events (about 5M at the moment, but there will be more). Each event has two attributes that I care about for this query - location (latitude and longitude pair) and relevancy . My goal is : For a given location bounds (SW / NE latitude/longitude pairs, so 4 floating point numbers) return the top 100 events by relevancy which fall within those bounds. I'm currently using the following query: select * from event where latitude >= :swLatitude and latitude <=

Does anyone know of potential problems with st_line_substring in postGIS?

不问归期 提交于 2020-01-07 03:11:10
问题 Specifically I'm getting a result that I do not understand. It is possible that my understanding is simply wrong, but I don't think so. So I'm hoping that someone will either say "yes, that's a known problem" or "no, it is working correct and here is why your understanding is wrong". Here is my example. To start I have the following geometry of lat/longs. LINESTRING(-1.32007599 51.06707497,-1.31192207 51.09430508,-1.30926132 51.10206677,-1.30376816 51.11133597,-1.29261017 51.12981493,-1