An example spatial lookup service. In-memory reverse geocode backed by GEOS.

Overview

Spatial Lookup Web Service

This GEOS example program demonstrates the use of the STRtree index and PreparedGeometry to create a high-performance in-memory reverse geocoder.

A generic reverse geocoder takes in coordinates and returns addresses. This simple application works with collections of polygons. It takes in a query coordinate and returns data from the polygons that the query intersects with.

How It Works

In order to efficiently search a large collection of polygons, the server applies two indexes to the collection:

When a coordinate comes in, the query is executed by:

  • First querying the STRtree, to find all geometries that have bounding boxes that intersect the coordinate.
  • Second for each geometry found, running the prepared geometry intersects() method to determine if the point is actually inside the geometry.

Basically the two indexes act at different levels. The STRtree indexes the bounds of all the polygons. The PreparedGeometry indexes the segments of each separate geometry.

Implementation Details

The lookup service is contained within the SpatialLookup class. This class holds the parsed GeoJSON objects, which in turn hold the properties list for each object. It also holds the STRtree index, and a vector of LookupEntry objects for each polygonal GeoJSONFeature.

Within the SpatialLookup class the LookupEntry class encapsulates the PreparedGeometry and GeoJSONFeature into a single object that can be added to the STRtree. This reduces the lookup code to the bare minimum:

  • find all entries in the STRtree that intersect the query,
  • check each entry for intersection,
  • read the desired property from the GeoJSON properties of each intersecting entry.

The HTTP interface is provided here by cpp-httplib, but it could be provided by any HTTP library you choose.

Building and Running

To build the code, create a clean build directory and then build. Using a separate build directory makes cleaning up build artifacts very easy.

mkdir _build
cd _build
cmake ..
make

To run the application, ensure you have a GeoJSON FeatureCollection file of polygons handy. (Use the example below, or download a state zip code file perhaps.)

Then run the executable, supplying the GeoJSON file name and the name of the property you want returned when your query point hits a polygon. For example, using a Maryland zipcode file:

# ./spatial_lookup md_maryland_zip_codes_geo.min.json ZCTA5CE10

./spatial_lookup loaded and indexed md_maryland_zip_codes_geo.min.json
./spatial_lookup listening on localhost:8080

Querying the service then looks like this:

curl "http://localhost:8080/lookup?x=-78.40&y=39.69"

["21766"]

Example GeoJSON File

Use "name" as your property.

./spatial_lookup geojson.json name

There two polygons surrounding the cell at 0,0.

curl http://localhost:8080/lookup?x=0.5&y=0.5

Example data for geojson.json file.

{ "type": "FeatureCollection",
  "features": [
    { "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [ [0.0, 0.0], [1.0, 0.0], [1.0, 1.0],
             [0.0, 1.0], [0.0, 0.0] ]
          ]
      },
      "properties": {
         "name": "Peter",
         "age": 50.8
      }
    },
    { "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [ [0.0, 0.0], [1.0, 0.0], [1.0, 1.0],
             [0.0, 1.0], [0.0, 0.0] ]
          ]
      },
      "properties": {
         "name": "Paul",
         "age": 50.8
      }
    },
    { "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [ [10.0, 10.0], [11.0, 10.0], [11.0, 11.0],
             [10.0, 11.0], [10.0, 10.0] ]
          ]
      },
      "properties": {
         "name": "Mary",
         "age": 50.8
      }
    }
  ]
}
You might also like...
ServiceLocator - Service Locator Pattern Header-Only Library

Service Locator Very fast, header-only C++ Service Locator Pattern library What is the Service Locator Pattern The Service Locator Pattern is a design

Implements a Windows service (in a DLL) that removes the rounded corners for windows in Windows 11

ep_dwm Implements a Windows service that removes the rounded corners for windows in Windows 11. Tested on Windows 11 build 22000.434. Pre-compiled bin

A simple PoC to demonstrate that is possible to write Non writable memory and execute Non executable memory on Windows

WindowsPermsPoC A simple PoC to demonstrate that is possible to write Non writable memory and execute Non executable memory on Windows You can build i

Memory Process File System (MemProcFS) is an easy and convenient way of viewing physical memory as files in a virtual file system
Memory Process File System (MemProcFS) is an easy and convenient way of viewing physical memory as files in a virtual file system

The Memory Process File System (MemProcFS) is an easy and convenient way of viewing physical memory as files in a virtual file system.

Thread Stack Spoofing - PoC for an advanced In-Memory evasion technique allowing to better hide injected shellcode's memory allocation from scanners and analysts.
Thread Stack Spoofing - PoC for an advanced In-Memory evasion technique allowing to better hide injected shellcode's memory allocation from scanners and analysts.

Thread Stack Spoofing PoC A PoC implementation for an advanced in-memory evasion technique that spoofs Thread Call Stack. This technique allows to byp

An advanced in-memory evasion technique fluctuating shellcode's memory protection between RW/NoAccess & RX and then encrypting/decrypting its contents
An advanced in-memory evasion technique fluctuating shellcode's memory protection between RW/NoAccess & RX and then encrypting/decrypting its contents

Shellcode Fluctuation PoC A PoC implementation for an another in-memory evasion technique that cyclically encrypts and decrypts shellcode's contents t

Block Cipher Reverse Engineering: A Challenge by Nintendo European Research & Development
Block Cipher Reverse Engineering: A Challenge by Nintendo European Research & Development

My algorithm cracks NERD HireMe for any output within 1 Second without Brute-Force! Read more if you want to find out how this was accomplished or execute this algorithm yourself on Wandbox - Online C++ Compiler

Powerful automated tool for reverse engineering Unity IL2CPP binaries
Powerful automated tool for reverse engineering Unity IL2CPP binaries

Powerful automated tool for reverse engineering Unity IL2CPP binaries

Owner
Paul Ramsey
@postgis core contributor, and general @postgres enthusiast. Mapping, spatial data, relational databases and architectures.
Paul Ramsey
A cross-platform framework for developing spatial audio algorithms and software in C/C++

git: https://github.com/leomccormack/Spatial_Audio_Framework doxygen: https://leomccormack.github.io/Spatial_Audio_Framework/ About The Spatial_Audio_

Leo McCormack 396 Dec 23, 2022
Fast glsl deNoise spatial filter, with circular gaussian kernel, full configurable

glslSmartDeNoise Fast glsl spatial deNoise filter, with circular gaussian kernel and smart/flexible/adaptable -> full configurable: Standard Deviation

Michele Morrone 212 Dec 24, 2022
Example-application - Example out-of-tree application that is also a module

Zephyr Example Application This repository contains a Zephyr example application. The main purpose of this repository is to serve as a reference on ho

Zephyr Project 82 Dec 13, 2022
New lateral movement technique by abusing Windows Perception Simulation Service to achieve DLL hijacking code execution.

BOF - Lateral movement technique by abusing Windows Perception Simulation Service to achieve DLL hijacking ServiceMove is a POC code for an interestin

Chris Au 190 Nov 14, 2022
This is Script tools from all attack Denial of service by C programming

RemaxDos Paltfrom Attack RemaxDos This is Script tools from all attack Denial of service Remax Box Team !. Features ! Cam overflow Syn Flooding. Smurf

null 7 Sep 11, 2022
Basic Windows Service managment API

SvcManager Basic Windows Service managment API A simple C++ Windows Service management API built my me. To be honest, I havent committed anything in a

Josh S. 4 Sep 8, 2022
This is the repo that hosts the code for Mozilla's translation service

Translation service HTTP service that uses bergamot-translator and compressed neural machine translation models for fast inference on CPU. Running loc

Mozilla 18 Sep 7, 2022
Cloud-native high-performance edge/middle/service proxy

Cloud-native high-performance edge/middle/service proxy Envoy is hosted by the Cloud Native Computing Foundation (CNCF). If you are a company that wan

Envoy Proxy - CNCF 21.2k Jan 9, 2023
Determine if the WebClient Service (WebDAV) is running on a remote system

GetWebDAVStatus Small project to determine if the Web Client service (WebDAV) is running on a remote system by checking for the presence of the DAV RP

null 66 Nov 28, 2022
A basic, MQTT integration point service for the Waveshare 8 channel relay board

relayboard-control A basic, MQTT integration point service for the Waveshare 8 channel relay board. This was built specifically for our own home's rel

Dan Leinir Turthra Jensen 2 Mar 22, 2022