Git Product home page Git Product logo

polygon-offsetting-for-geofencing's Introduction

Polygon Offsetting for Geofencing

This repo contains a Python and a MATLAB script for generating offset polygons from a set of 2D coordinates. The scripts were originally developed for geofencing purposes, but can be applied for other uses as well.

Description

The script polygon_offset.py for Python and polygon_offset.m for MATLAB takes a set of 2D coordinates that make a polygon, an offseting distance, and a desired direction (inward or outward) to calculate new coordinates that make an offset polygon. The python script is more advanced than the one in MATLAB as it uses the utm library for Python to convert latitude and longitude coordinates to UTM coordinates, and performs the offset calculation in UTM space. The script returns the offset polygon in lat/long and UTM coordinates. The script in MATLAB doesn't have the capability of working with latitude/longitude coordinates. However, one could use the matlab function utmconv for that purpose.

Inputs

  • polygon: 2D array containing the coordinates of all vertices of a polygon
  • offset: desired offset distance
  • direction: direction at which the offset is desired ('i' for inward or 'o' for outward)
  • zone and letter: UTM zone at which the lat/long coordinates were collected (python script only)

Outputs

  • 2D array containing the coordinates of all vertices of the offset polygon (lat/long and UTM)

Dependencies

The Python script has the following dependencies:

  • numpy
  • utm

Usage

Python

import polygon_offset

geofence = [[latitude_coordinates],[longitude_coordinates]]
offset = 10
direction = 'o' # Outward (expansion)
zone = 10
letter = 'N'

offset_polygon = polygon_offset(geofence, offset, direction, zone, letter)

Matlab

geofence = [[latitude_coordinates],[longitude_coordinates]]
offset = 10
direction = 'o' # Outward (expansion)
offset_polygon = polygon_offset(geofence, offset, direction)

Limitations

  • Script assumes that the input polygon is closed, i.e., the first and last vertex are the same.
  • Script assumes that the input polygon is simple, i.e., it does not self-intersect
  • The script only works with 2D polygons.

Examples

  • The repository includes example excel files with latitude/longitude coordinates of buildings and a roundabout that can be used to demonstrate the usage of the python script. Below are a few screenshots from the outputs of the python script:

Polygon expansion:

python_example_1 python_example_2 python_example_3 python_example_4

Polygon contraction:

python_example_5 python_example_6 python_example_7 python_example_8

  • In addition, this repository includes a MATLAB file (Polygon_ofsett_demo.m) that demonstrates the usage of the MATLAB script.Below is a screenshot from the output of the MATLAB demo file: matlab_example

References

[1] https://stackoverflow.com/questions/54033808/how-to-offset-polygon-edges

Contributions

If you would like to contribute to this project, please contact the author.

License

This project is licensed under the terms of the MIT license.

Please let me know if there's anything else I can help you with.

polygon-offsetting-for-geofencing's People

Contributors

guilhermedemouraa 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.