基于django的web_使用Django和GeoDjango制作基于位置的Web应用

基于django的web

Throughout this tutorial, you’ll learn how to use Django and GeoDjango to build a location-based web application from scratch. You’ll be building a simple nearby shops application that lists the shops closest to a user’s location.

在整个教程中,您将学习如何使用Django和GeoDjango从头开始构建基于位置的Web应用程序。 您将构建一个简单的附近商店应用程序,该应用程序列出距离用户位置最近的商店。

By the end of this tutorial, you’ll be able to:

在本教程结束时,您将能够:

  • Use Django to build a simple web application from scratch

  • Use the GeoDjango sub-framework to implement geolocation features in your Django application

  • Use a spatial database (PostgreSQL and PostGIS) to get benefits from the spatial features and easily implement location-aware web apps

  • 使用Django从头构建一个简单的Web应用程序

  • 使用GeoDjango子框架在Django应用程序中实现地理定位功能

  • 使用空间数据库(PostgreSQL和PostGIS)从空间功能中受益,并轻松实现位置感知的Web应用程序

Free Bonus: Click here to get free access to additional Django tutorials and resources you can use to deepen your Python web development skills.

免费红利: 单击此处可免费访问其他Django教程和资源,您可以使用它们来加深Python Web开发技能。

您将使用的工具 (The Tools You Will Be Using)

You’ll be using the following tools to develop your nearby shops web application:

您将使用以下工具来开发附近的商店Web应用程序:

  • The Python programming language
  • The Django web framework
  • The PostgreSQL database for persisting data
  • The PostGIS extension for supporting spatial features in the PostgreSQL database
  • pip for installing dependencies
  • The venv module for managing a virtual environment
  • Docker for installing PostgreSQL and PostGIS
  • Python程式设计语言
  • Django Web框架
  • PostgreSQL数据库用于持久存储数据
  • PostGIS扩展,用于支持PostgreSQL数据库中的空间特征
  • 用于安装依赖项的pip
  • venv模块,用于管理虚拟环境
  • 用于安装PostgreSQL和PostGIS的Docker

Used tools

Before diving into practical steps, let’s first start by introducing the frameworks you’ll be using.

在进入实际步骤之前,让我们首先开始介绍您将要使用的框架。

Django is the most popular Python framework for building web apps. It makes it easy for developers to quickly build prototypes and meet their project deadlines by providing a plethora of built-in APIs and sub-frameworks such as GeoDjango.

Django是用于构建Web应用程序的最受欢迎的Python框架。 通过提供大量的内置API和子框架(例如GeoDjango),开发人员可以轻松地快速构建原型并按时完成项目。

GeoDjango is a built-in application that is included as a contrib module in Django. It’s actually a complete framework itself that can also be used separately from Django. It provides a toolbox of utilities for building GIS web applications.

GeoDjango是一个内置应用程序,包含在Django中作为contrib模块。 它实际上是一个完整的框架,也可以与Django分开使用。 它提供了用于构建GIS Web应用程序的实用工具箱。

GIS stands for Geographic Information System. It’s an information system (an organized system for the collection, organization, storage, and communication of information) designed for processing and manipulating data that have geographic or spatial characteristics.

GIS代表地理信息系统。 它是一个信息系统( 用于信息的收集,组织,存储和通信的有组织的系统 ),旨在处理和处理具有地理或空间特征的数据。

GeoDjango also provides Python bindings to popular spatial libraries such as GEOS, GDAL, and GeoIP, which can be used separately without Django in any Python application or interactively in the shell.

GeoDjango还提供了对流行的空间库(例如GEOSGDALGeoIP)的 Python绑定,这些库可以在没有Django的情况下在任何Python应用程序中单独使用或在外壳中交互使用。

GeoDjango aims to provide a world-class geographic web framework. It has been refactored over the years with the goal of making it easier to work with geospatial data, in other words data that identifies the geographic location of natural or artificial features on Earth and is stored as coordinates and topologies.

GeoDjango旨在提供世界一流的地理网络框架。 多年来已对其进行了重构,其目标是使其更易于使用地理空间数据,换句话说,该数据可识别地球上自然或人工特征的地理位置并存储为坐标和拓扑。

GeoDjango integrates very well with the Django ORM and provides a set of geometry fields defined by the Open Geospatial Consortium (OGS) that can be used to map to different types of geometries in geospatial databases:

GeoDjango与Django ORM很好地集成在一起,并提供了由开放地理空间联盟(OGS)定义的一组几何字段,可用于映射到地理空间数据库中的不同类型的几何:

GeoDjango is a very powerful framework for storing and working with geographic data using the Django ORM. It provides an easy-to-use API to find the distances between two points on a map, areas of polygons, the points within a polygon, and so on.

GeoDjango是一个非常强大的框架,用于使用Django ORM存储和处理地理数据。 它提供了易于使用的API,可查找地图上两个点之间的距离,多边形的区域,多边形内的点等。

To be able to work with GeoDjango, you’ll need to have two things: a spatial database and geospatial libraries. A spatial database is a database that is optimized for storing and querying data that represents objects defined in a geometric space.

为了能够与GeoDjango一起使用,您需要具备两件东西:空间数据库和地理空间库。 空间数据库是为存储和查询表示几何空间中定义的对象的数据而优化的数据库。

To fully use all features of GeoDjango, you’ll need to install the following open-source geospatial libraries:

要完全使用GeoDjango的所有功能,您需要安装以下开源地理空间库:

  • GEOS stands for Geometry Engine Open Source. It’s a C++ port of the JTS (Java Topology Suite) that implements the OCG Simple Feature for SQL specification.

  • GDAL stands for Geospatial Data Abstraction Library. It’s an open-source library for working with raster and vector geospatial data formats.

  • PROJ.4 is for Cartographic Projections library. It’s an open-source GIS library for easily working with spatial reference systems and projections.

  • GeoIP is a library that helps users find geographical information based on an IP address.

  • GEOS代表“几何引擎开源”。 它是JTS(Java拓扑套件)的C ++端口,实现了用于SQL规范OCG简单功能

  • GDAL代表地理空间数据抽象库。 这是一个用于处理栅格和矢量地理空间数据格式的开源库。

  • PROJ.4用于制图投影库。 这是一个开源GIS库,可轻松使用空间参考系统和投影。

  • GeoIP是一个库,可帮助用户根据IP地址查找地理信息。

This tutorial makes use of an Ubuntu 18.04 system for installing prerequisites and a Unix bash for running the commands, but this shouldn’t be a problem for you if you’re using any other system, particularly Unix-based systems like macOS.

本教程利用Ubuntu 18.04系统安装必备软件,并使用Unix bash运行命令,但是如果您使用任何其他系统,尤其是基于macOS的基于Unix的系统,这对您来说应该不是问题。

For most installation instructions, you’ll be using the aptitude package manager, so you should simply replace that with the equivalent package manager for your system.

对于大多数安装说明,将使用aptitude软件包管理器,因此您只需将其替换为系统的等效软件包管理器即可。

先决条件 (Prerequisites)

In this section, you’ll be installing the prerequisites needed before you can bootstrap your project, such as Python 3 and GeoDjango dependencies (GEOS, GDAL, and PROJ.4). You’ll also use Docker to set up a PostgreSQL and PostGIS database for your project.

在本节中,您将安装所需的先决条件,然后才能引导您的项目,例如Python 3和GeoDjango依赖项(GEOS,GDAL和PROJ.4)。 您还将使用Docker为您的项目设置PostgreSQL和PostGIS数据库。

安装Python 3 (Installing Python 3)

There is a big chance that you already have Python 3 installed on your system. If you don’t, you can simply head to the official website and download the binaries for your operating system.

您很有可能已经在系统上安装了Python 3。 如果没有,您可以直接访问官方网站并下载适用于您的操作系统的二进制文件。

Depending on your system, you may also be able to install Python 3 or upgrade it to the latest version if it’s already installed by using the official package manager.

根据您的系统,您可能还可以安装Python 3或将其升级到最新版本(如果已经使用官方软件包管理器安装了该版本)。

If you have a problem installing Python 3 or want more information, you can check the Python 3 Installation & Setup Guide, which provides different ways to install Python 3 on your system.

如果您在安装Python 3时遇到问题或需要更多信息,可以查看《 Python 3安装和设置指南》 ,该指南提供了在系统上安装Python 3的不同方法。

Finally, you can check if you have Python 3 installed by running the following command:

最后,您可以通过运行以下命令来检查是否已安装Python 3:

 $ python3 --version
$ python3 --version
Python 3.6.5
Python 3.6.5

安装GeoDjango依赖关系(GEOS,GDAL和PROJ.4) (Installing GeoDjango Dependencies (GEOS, GDAL, and PROJ.4))

GeoDjango requires a spatial database and a set of open-source geospatial libraries:

GeoDjango需要一个空间数据库和一组开源地理空间库:

  • GEOS is an open-source geometry engine and a C++ port of the JTS (Java Topology Suite). It’s required by GeoDjango for performing geometric operations.

  • PROJ.4 is an open-source GIS library for easily working with spatial reference systems and projections. You need it because you’ll be using PostGIS as the spatial database.

  • GDAL is an open-source geospatial data abstraction library for working with raster and vector data formats. It’s needed for many utilities used by GeoDjango.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值