Giter VIP home page Giter VIP logo

btl-htttdl-nhom13's Introduction

BTL-HTTDL-Nhom13

Mã nguồn BTL môn HTTT Địa Lý - Nhóm 13 - ĐH Thuỷ Lợi

image

Tài liệu hoạt động nhóm: https://vietthao2000.notion.site/BTL-HTTT-a-L-Nh-m-13-0971c386d2d14e59a49c9b4af6dec33b

I. Công nghệ sử dụng

II. Mô tả tính năng:

II.1. Tìm kiếm địa điểm:

  1. Người dùng chọn vị trí A, bán kính tìm kiếm R, vùng tìm kiếm và loại địa điểm
  2. Query các địa điểm thoả mãn nằm trong bán kính R và trong vùng tìm kiếm (nếu người dùng không chọn vùng tìm kiếm thì tìm kiếm trên mọi vùng)
  3. Hiển thị kết quả lên bản đồ

II.2. Tìm đường đi ngắn nhất:

  1. Người dùng click chọn một địa điểm B trong tập những điểm đã hiển thị ở bước trên
  2. Query tập các con đường đi từ A đến B, sort theo độ dài
  3. Chọn đường đi ngắn nhất

III. Hướng dẫn sử dụng

III.1. Import và khởi tạo dữ liệu tìm đường đi ngắn nhất

  1. Import 3 shapefile sau vào database bằng PostGIS:
  • gadm41_VNM_2.shp: Dữ liệu địa giới hành chính Việt Nam
  • gis_osm_pois_free_1.shp: Dữ liệu địa điểm (point of interests) Việt Nam, phục vụ cho việc tìm địa điểm
  • hanoi_round.shp: Dữ liệu đường trong khu vực Hà Nội phục vụ cho tìm đường đi ngắn nhất
  1. Mở PGAdmin lên và chạy các query sau:
# Thêm extension cần thiết để thực hiện routing
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION pgrouting;

# Thêm cột source và target, đánh index
ALTER TABLE hanoi_round ADD COLUMN source integer;
ALTER TABLE hanoi_round ADD COLUMN target integer;
CREATE INDEX source_idx ON hanoi_round(source);
CREATE INDEX target_idx ON hanoi_round(target);

# Xoá các hàng mà cột source bị null
DELETE FROM hanoi_round WHERE source is null;

# Thêm toạ độ điểm bắt đầu và kết thúc của mỗi đoạn đường
ALTER TABLE hanoi_round ADD COLUMN x1 double precision;
ALTER TABLE hanoi_round ADD COLUMN y1 double precision;
ALTER TABLE hanoi_round ADD COLUMN x2 double precision;
ALTER TABLE hanoi_round ADD COLUMN y2 double precision;

UPDATE hanoi_round SET x1=ST_X(ST_StartPoint(ST_LineMerge(geom)));
UPDATE hanoi_round SET y1=ST_Y(ST_StartPoint(ST_LineMerge(geom)));
UPDATE hanoi_round SET x2=ST_X(ST_EndPoint(ST_LineMerge(geom)));
UPDATE hanoi_round SET y2=ST_Y(ST_EndPoint(ST_LineMerge(geom)));

# Khai báo hàm A* tìm đường đi ngắn nhất
CREATE OR REPLACE FUNCTION pgr_fromAtoB(
    IN edges_subset varchar,
    IN x1 double precision,
    IN y1 double precision,
    IN x2 double precision,
    IN y2 double precision,
    OUT seq INTEGER,
    OUT cost FLOAT,
    OUT name TEXT,
    OUT geom geometry,
    OUT heading FLOAT
)
RETURNS SETOF record AS
$BODY$

WITH
    astar AS (
        SELECT * FROM pgr_aStar(
            'SELECT gid as id, source, target, st_length(geom) AS cost FROM ' || $1,
            -- source
            (SELECT id FROM hanoi_round_vertices_pgr
                ORDER BY the_geom <-> ST_SetSRID(ST_Point(x1,y1),4326) LIMIT 1),
            -- target
            (SELECT id FROM hanoi_round_vertices_pgr
                ORDER BY the_geom <-> ST_SetSRID(ST_Point(x2,y2),4326) LIMIT 1),
        false) -- undirected
    ),
    with_geom AS (
        SELECT astar.seq, astar.cost, hanoi_round.name,
        CASE
            WHEN astar.node = hanoi_round.source THEN geom
            ELSE ST_Reverse(geom)
        END AS route_geom
        FROM astar JOIN hanoi_round
        ON (edge = gid) ORDER BY seq
    )
    SELECT *,
    ST_azimuth(ST_StartPoint(route_geom), ST_EndPoint(route_geom))
    FROM with_geom;
$BODY$
LANGUAGE 'sql';
  1. Vào GeoServer dashboard. Chọn Layers -> Add a new layer -> Chọn workspace tương ứng -> Configure new SQL view...

image

  1. Điền
SELECT (route.geom) FROM 
    (SELECT geom FROM pgr_fromAtoB('hanoi_round', %x1%, %y1%, %x2%, %y2%) ORDER BY seq)
AS route
  1. Chọn Guess parameters from SQL, nhập Default value = 0 và Validation regular expression = ^-?[\d.]+$

image

  1. Trong phần Attributes, ấn Refresh, trong Type chọn LineString, SRID chọn hệ tọa độ của data, ở đây là 4326.

image

  1. Nhấn Save. Tiếp theo chúng ta điền các thông tin khác cho layer. Bạn có thể không cần điền thêm gì, chỉ cần ấn Compute from data và Compute from native bounds để tạo bộ khung cho layer.

image

III.2. Config XAMPP server

  1. Copy thư mục src vào htdocs trong XAMPP server, đổi thành tên tuỳ ý
  2. Copy file constant.php.example thành constant.php, sửa TABLENAME và PASSWORD tương ứng với database mà bạn vừa import shapefiles vào.

image

  1. Start XAMPP server

image

III.3. Truy cập ứng dụng

  • Truy cập ứng dụng bằng đường dẫn http

image

btl-htttdl-nhom13's People

Contributors

t-rekttt avatar vungn avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.