MySQL 支持GeoDjango的简单说明

14 篇文章 0 订阅

配置GeoDjango的具体过程可参考官方文档:

https://docs.djangoproject.com/en/1.9/ref/contrib/gis/


1.安装

(1)安装GEOS

Database

Library Requirements

Supported Versions

Notes

PostgreSQL

GEOS, PROJ.4, PostGIS

9.1+

Requires PostGIS.

MySQL

GEOS

5.5+

Not OGC-compliant.

Oracle

GEOS

11.2+

XE not supported.

SQLite

GEOS, GDAL, PROJ.4, SpatiaLite

3.6.+

Requires SpatiaLite 2.4+, pysqlite2 2.5+

 

从上表可知:对于MySQL,只需安装GEOS;

           对于PostgreSQL,需要安装PROJ.4、PostGIS

           对于SQLite,需安装PROJ.4、GDAL、SpatiaLite

 

GEOS是一个支持空间几何运算C++库,关于它的详细介绍,可参考官方文档:

https://docs.djangoproject.com/en/1.9/ref/contrib/gis/install/geolibs/

 

MySQL没有完全支持OGC标准,所以对空间数据的CRUD会有一些限制,详细可参考文档:

https://docs.djangoproject.com/en/1.9/ref/contrib/gis/db-api/#mysql-spatial-limitations

 

由于目前我们服务器上使用的是MySQL,所以按MySQL进行配置:安装GEOS

先下载geos

$ wget http://download.osgeo.org/geos/geos-3.4.2.tar.bz2
$ tar xjf geos-3.4.2.tar.bz2

然后解压、编译、安装

$ cd geos-3.4.2
$ ./configure
$ make
$ sudo make install
$ cd ..

执行完上述几步,想知道GEOS是否安装正确,可用下面的命令:

进入python shell,键入下面的命令,如果不报错,则认为安装正确。

from django.contrib.gis.dbimport models

(2)修改settings.py

a.  在INSTALLED_APPS中添加 'django.contrib.gis',

b. 修改数据库引擎为  'ENGINE': 'django.contrib.gis.db.backends.mysql',

(3)在models.py中引入models

from django.contrib.gis.db import models

同时可以注释掉from django.db import models

(4)测试:

在models.py(比如Person表)中,添加以下字段:

point = models.PointField(null=True,blank=True)

然后运行: 

./manage.py makemigrations

如果不报错,则视为正确。

除了PointField以外,还有多个空间类型,如下:

具体可参考GeoDjango Models API的文档:

https://docs.djangoproject.com/en/1.9/ref/contrib/gis/model-api/#spatial-field-types

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值