PostGIS

How do I get the k nearest neighbors for geodjango?

老子叫甜甜 提交于 2021-01-24 09:21:31
问题 Assume that I have the following model: class Person: id = models.BigAutoField(primary_key=True) name = models.CharField(max_length=150) location = models.PointField() How would I go by obtaining the k nearest neighbors (KNN) by location using geodjango? Would I have to write custom SQL for that? I am using PostgreSQL with PostGIS. 回答1: You can use a raw() sql query to utilize postgis order_by operators: <-> which gets the nearest neighbor using the centers of the bounding boxes to calculate

How do I get the k nearest neighbors for geodjango?

别等时光非礼了梦想. 提交于 2021-01-24 09:20:40
问题 Assume that I have the following model: class Person: id = models.BigAutoField(primary_key=True) name = models.CharField(max_length=150) location = models.PointField() How would I go by obtaining the k nearest neighbors (KNN) by location using geodjango? Would I have to write custom SQL for that? I am using PostgreSQL with PostGIS. 回答1: You can use a raw() sql query to utilize postgis order_by operators: <-> which gets the nearest neighbor using the centers of the bounding boxes to calculate

How do I get the k nearest neighbors for geodjango?

自古美人都是妖i 提交于 2021-01-24 09:18:51
问题 Assume that I have the following model: class Person: id = models.BigAutoField(primary_key=True) name = models.CharField(max_length=150) location = models.PointField() How would I go by obtaining the k nearest neighbors (KNN) by location using geodjango? Would I have to write custom SQL for that? I am using PostgreSQL with PostGIS. 回答1: You can use a raw() sql query to utilize postgis order_by operators: <-> which gets the nearest neighbor using the centers of the bounding boxes to calculate

Creating a table for Polygon values in Postgis and inserting

橙三吉。 提交于 2021-01-21 05:16:05
问题 I have the following area "name" and "polygon" values for 10 different areas ('A',50.6373 3.0750,50.6374 3.0750,50.6374 3.0749,50.63 3.07491,50.6373 3.0750) I want to create a table in postgres DB using POSTGIS Later, I will have lan and lat values (e.g. 50.5465 3.0121) in a table to compare with the above table and pull out the area name Can you help me with the code for both creating and inserting the polygon coordinates? 回答1: I don't have enough reputation to comment you question, there is

SHP文件导入PostGIS

白昼怎懂夜的黑 提交于 2021-01-02 12:11:50
shp转换成sql文件: CD "C:\Program Files (x86)\PostgreSQL\9.2\bin"​​ shp2pgsql -d -g "shape" -s 4326 -W "GBK" D:\Data\bou2_4m\bou2_4l.shp tablename > c:\tablename.sql ​-d:删除然后创建 -g:空间字段的名称 -s:空间参考 -W:字符编码 SQL 入库: CD "C:\Program Files (x86)\PostgreSQL\9.2\bin" psql -h localhost -p 5432 -U postgres -w -d "DPRS" -f "c:\tablename.sql" -h : IP地址 -p : 端口号 -U : 用户名 -w : 不输入密码 -d : 数据库名称 -f : 后面跟需要执行的sql文件 来源: oschina 链接: https://my.oschina.net/u/1453406/blog/472063

CREATE EXTENSION postgis fails,

早过忘川 提交于 2020-12-31 04:45:32
问题 I am on Ubuntu 18.04 with the psql (PostgreSQL) 12.2 (Ubuntu 12.2-2.pgdg18.04+1) Running temba=# create extension postgis; fails with the following error ERROR: could not open extension control file "/usr/share/postgresql/10/extension/postgis.control": No such file or directory I ran find /usr -name postgis.control only to find out postgis.control is inside a folder named 12 instead of 10 laptop@xyz-x:~$ find /usr -name postgis.control /usr/share/postgresql/12/extension/postgis.control Edit 1

CREATE EXTENSION postgis fails,

不羁的心 提交于 2020-12-31 04:44:28
问题 I am on Ubuntu 18.04 with the psql (PostgreSQL) 12.2 (Ubuntu 12.2-2.pgdg18.04+1) Running temba=# create extension postgis; fails with the following error ERROR: could not open extension control file "/usr/share/postgresql/10/extension/postgis.control": No such file or directory I ran find /usr -name postgis.control only to find out postgis.control is inside a folder named 12 instead of 10 laptop@xyz-x:~$ find /usr -name postgis.control /usr/share/postgresql/12/extension/postgis.control Edit 1

Importing shapefiles in postgresql in linux using pgadmin 4

孤人 提交于 2020-12-26 08:23:06
问题 I am new to postGIS, I was following this tutorial. I can't get past the installation part because the instructions are outdated. I got stuck when it says return to the Dashboard, and click on the Import shapefiles link in the PostGIS section. I am using pgadmin 4 and I am unable to find the postGIS section there. 回答1: If you're simply trying to import shapefiles into PostgreSQL, you might wanna take a look at shp2pgsql. Data sample: TM_WORLD_BORDERS_SIMPL-0.3.zip After unpacking your zip

如何查找并下载rpm依赖包并使用yum离线安装rpm包

∥☆過路亽.° 提交于 2020-12-22 07:59:44
每一个成功人士的背后,必定曾经做出过勇敢而又孤独的决定。 放弃不难,但坚持很酷~ Linux版本:CentOS Linux release 7.3.1611 (Core) 一、需求 最近在工作中需要postgresql + postgis的离线安装。安装有两种方式: 源码编译 rpm包安装 源码编译耗费时间长,缺乏编译环境且生成目录位置不详,所以选择使用rpm包安装。但是我们最终目的是rpm包离线安装,目前不知道安装postgresql + postgis所依赖的rpm包有哪些,并且从网上找rpm包容易引起版本冲突啊,怎么办呢? 办法总比问题多,接着往下看。 二、在线安装 通过下载外部repo源的安装方式,我这里暂且称之为在线安装。 我们首先要使用在线安装的方式,成功安装postgresql + postgis,然后再考虑如何获取相关依赖rpm包的问题。请看具体命令: # 安装postgresql依赖的rpm包 rpm -ivh https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm # 安装postgis的依赖包 rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest

postgresql+postgis+pgrouting安装(windows10)

只谈情不闲聊 提交于 2020-12-18 03:14:00
注:a. 以下安装皆指windows系统   b.只要安装了postgis,pgrouting自带就安装上了 一。postgresql版本10.9,posttgis版本2.5,pgrouting版本2.6( 三者版本必须对应!!! ) --查看postgresql版本 show server_version; --查看postgis版本 SELECT PostGIS_full_version(); --查看pgrouting版本 select pgr_version(); 二。安装文件下载地址( 点我下载 ),提取码:j2f8,下载文件名称:postgresql-10.9-2-windows-x64.exe,postgis-bundle-pg10x64-setup-2.5.2-1.exe 三。windows7,windows8安装参考   https://blog.csdn.net/antma/article/details/83579920 四。windows10安装步骤如下   4-1.postgresql安装:按照  上述所说的windows7,windows8安装方式正常安装 https://blog.csdn.net/antma/article/details/83579920 注:很大概率会报错: Problem running post-install step.