当前位置:网站首页>A preliminary study of geojson
A preliminary study of geojson
2022-07-06 00:39:00 【Goodbye, Monkey King】
Recently, when doing data visualization , Mentioned a kind of GeoJSON Formatted data , Here is a comb .
1 brief introduction
GeoJSON It is a format for encoding various geographic data structures .GeoJSON Objects can represent geometry 、 A feature or set of features .GeoJSON The following geometry types are supported : spot 、 Line 、 Noodles 、 Multipoint 、 Multi line 、 Polyhedra and geometric sets .GeoJSON The feature in contains a geometric object and other attributes , A feature set represents a series of features .
A complete GeoJSON The data structure is always a (JSON In terms of ) object . stay GeoJSON in , Object by name / It's worth it -- Also known as the set composition of members .
example :
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.0, 0.5]
},
"properties": {
"prop0": "value0"
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[102.0, 0.0],
[103.0, 1.0],
[104.0, 0.0],
[105.0, 1.0]
]
},
"properties": {
"prop0": "value0",
"prop1": 0.0
}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
},
"properties": {
"prop0": "value0",
"prop1": {
"this": "that"
}
}
}
]
}2 GeoJSON object
GeoJSON Always consists of a single object . This object ( It means the following GeoJSON object ) Represents geometry 、 A feature or set of features .
- GeoJSON Object can have any number of members ( name / It's worth it ).
- GeoJSON The object must have a name of "type" Members of . The value of this member is determined by GeoJSON The string determined by the type of the object .
- type The value of the member must be one of the following :"Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Feature", perhaps "FeatureCollection".
- GeoJSON Object may have an optional "crs" member , Its value must be an object of a coordinate reference system .
- GeoJSON The object may have a "bbox" member , Its value must be an array of bounding boxes .
Can be in http://geojson.io See the effect
2.1 Geometry object
Geometry is a kind of GeoJSON object , At this time type The value of the member is one of the following strings :"Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", perhaps "GeometryCollection".
except “GeometryCollection” Any other type of GeoJSON Geometric objects must have a name of "coordinates" Members of .coordinates The value of a member is always an array . The structure of the elements in this array is determined by the geometric type .
2.1.1 spot Point
{
"type": "Point",
"coordinates": [100.0, 0.0]
}2.1.2 Multipoint MultiPoint
{
"type": "MultiPoint",
"coordinates": [
[100, 0],
[101, 1]
]
}2.1.3 Line LineString
{
"type": "LineString",
"coordinates": [
[100, 0],
[101, 1]
]
}2.1.4 Multi line MultiLineString
{
"type": "MultiLineString",
"coordinates": [
[ [100.0, 0.0], [101.0, 1.0] ],
[ [102.0, 2.0], [103.0, 3.0] ]
]
}2.1.5 polygon Polyon
Nonporous
{
"type": "Polygon",
"coordinates": [
[
[ 100, 0 ],
[ 101, 0 ],
[ 101, 1 ],
[ 100, 1 ],
[ 100, 0 ]
]
]
}Porous
{
"type": "Polygon",
"coordinates": [
[
[ 100, 0 ],
[ 101, 0 ],
[ 101, 1 ],
[ 100, 1 ],
[ 100, 0 ]
],
[
[ 100.2, 0.2 ],
[ 100.8, 0.2 ],
[ 100.8, 0.8 ],
[ 100.2, 0.8 ],
[ 100.2, 0.2 ]
]
]
}2.1.6 Compound polygon MultiPolyon
Disjoint polygons
{
"type": "MultiPolygon",
"coordinates": [
[
[
[109.2041015625, 30.088107753367257],
[115.02685546875, 30.088107753367257],
[115.02685546875, 32.7872745269555],
[109.2041015625, 32.7872745269555],
[109.2041015625, 30.088107753367257]
]
],
[
[
[112.9833984375, 26.82407078047018],
[116.69677734375, 26.82407078047018],
[116.69677734375, 29.036960648558267],
[112.9833984375, 29.036960648558267],
[112.9833984375, 26.82407078047018]
]
]
]
}Two nested polygons
{
"type": "MultiPolygon",
"coordinates": [
[
[
[101.6455078125, 27.68352808378776],
[114.78515624999999, 27.68352808378776],
[114.78515624999999, 35.209721645221386],
[101.6455078125, 35.209721645221386],
[101.6455078125, 27.68352808378776]
]
],
[
[
[104.2822265625, 30.107117887092357],
[108.896484375, 30.107117887092357],
[108.896484375, 33.76088200086917],
[104.2822265625, 33.76088200086917],
[104.2822265625, 30.107117887092357]
]
]
]
}Polygons with holes
{
"type": "MultiPolygon",
"coordinates": [
[
[
[101.6455078125, 27.68352808378776],
[114.78515624999999, 27.68352808378776],
[114.78515624999999, 35.209721645221386],
[101.6455078125, 35.209721645221386],
[101.6455078125, 27.68352808378776]
],
[
[104.2822265625, 30.107117887092357],
[108.896484375, 30.107117887092357],
[108.896484375, 33.76088200086917],
[104.2822265625, 33.76088200086917],
[104.2822265625, 30.107117887092357]
]
]
]
}2.1.7 Geometric set GeometryCollection
It is a collection of many basic geographical elements , It can contain points 、 Line 、 Surface elements
{
"type": "GeometryCollection",
"geometries": [{
"type": "Point",
"coordinates": [108.62, 31.02819]
}, {
"type": "LineString",
"coordinates": [
[108.896484375, 30.1071178870],
[108.2184375, 30.91717870],
[109.5184375, 31.2175780]
]
}]
}2.2 Characteristic object
- The type is Feature Of GeoJSON An object is a feature object
- The feature object must have a name of "geometry" Members of , The value of this geometric member is the geometric object defined above or JSON Of null value .
- Feature to play that must have a name for “properties" Members of , The value of this property member is an object ( whatever JSON Object or JSON Of null value )
{
"type":"Feature",
"properties":{},
"geometry":{ "type": "Point", "coordinates": [100.0, 0.0] }
}2.3 Feature set object
- Feature set object type by FeatureCollection.
- The feature set object must have a name "features" Members of . And “features" The corresponding value is an array . Each element in this array is a feature object defined above .
{
"type": "FeatureCollection",
"features": []
}3 Application in various databases
3.1 mysql
1 geometry type
MySQL Provides data types geometry Used to store coordinate information ,geometry Type supports the following three kinds of data storage
data structure | Example | explain |
POINT( spot ) | POINT(113.3 40.08) | Used to store point information , Contains longitude and latitude information |
LINESTRING( Line ) | LineString(84.070 33.801,99.52 30.292) | Used to store route information |
POLYGON( Noodles ) | POLYGON((84.070 33.801, 84.100 33.801,84.070 33.801)) | Used to store face data |
2 Format spatial data type
The plaintext structure of the spatial data stored in the database displayed by the visualization tool is as seen in the above example , The structure is not easy to be parsed by the client , therefore MySQL Several spatial functions are provided to parse and format spatial data ,geojson yes gis Standard format for spatial data presentation , The front-end map framework and the related framework of back-end spatial analysis will support geojson Format
operation | function |
geojson -> geometry | ST_GeomFromGeoJSON |
geometry -> geojson | ST_ASGEOJSON |
geometry character string -> geometry | ST_GEOMFROMTEXT |
3 Example
new table
CREATE TABLE `geojson` (
`id` int(0) NOT NULL AUTO_INCREMENT,
`geojson` geometry NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;insert data
insert into geojson(geojson) VALUES (ST_GeomFromGeoJSON('{"type": "Point", "coordinates": [121.0, 31.0]}'));Inquire about
select id,ST_AsGeoJSON(geojson) as geojson from geojson;Common space functions
name | describe |
ST_INTERSECTS() | Judge whether two geometries intersect |
ST_DISTANCE() | The distance between two geometries |
ST_CONTAIONS() | Whether the geometry contains |
ST_ISVALID() | Is geometry valid |
ST_WITHIN() | Whether geometry is inside , Results and ST_CONTAIONS() contrary |
SELECT
id,
ST_AsGeoJSON ( geojson ) AS geojson
FROM
geojson
WHERE
ST_CONTAINS (
ST_GeomFromText ( 'POLYGON((100 30,120 30,120 36,100 36,100 30))' ),
geojson
)3.2 mongodb
1 Support geospatial index
- 2dsphere Indexes
- Used on maps of the earth's surface type
- It can be used in Legacy Coordinate Paris Save the latitude and longitude field and use GeoJSON Format saved points 、 Line 、 Polygon field
db.world.ensureIndex({"geometry" : "2dsphere"})- 2d Indexes
- For aspheric surfaces ( Game map , Time continuous data, etc ), have access to 2d Index substitution 2dsphere
- Support flat queries and some spherical queries , But spherical support is not very good
- Only points can be indexed
2 Support geospatial query
Main support intersection (intersection), contain (within), And close to (nearness)
- $geoIntersects
- Point out the document intersecting with the query location
- Support operators
- $geometry Appoint GeoJSON Format geometry
- $geoWithin
- Point out the documents completely contained in a certain area
- Support operators
- $box
- Find all documents within the rectangle
- $center
- Find out all documents within the circle
- $polygon
- Find out all documents within the polygon
- $centerSphere
- Query all documents within the sphere circle
- $geometry
- Appoint GeoJSON Format geometry
- $box
- $near
- Point out the document from the nearest to the farthest from the query location
- Support operators
- $maxDistance
- Specify the maximum distance of query results
- $minDistance
- Specify the minimum distance of query results
- $geometry
- Appoint GeoJSON Format points
- $maxDistance
- $nearSphere
- Use spherical geometry to calculate the distance near the spherical surface , Point out the document from the nearest to the farthest from the query location
- Support operators
- $maxDistance
- Specify the maximum distance of query results
- $minDistance
- Specify the minimum distance of query results
- $geometry
- Appoint GeoJSON Format points
- $maxDistance
Query documents with intersecting positions
db.getCollection('GeoEntity').find({
location: {
$geoIntersects: {
$geometry: {
type: "Polygon" ,
coordinates: [
[ [ 30, 20 ], [ 30, 40 ], [ 40, 40 ],[ 40, 20 ],[ 30, 20 ]]
]
}
}
}
})Query cross location documents
db.getCollection('GeoEntity').find({ location: { $geoWithin: { $box: [ [ 30, 30 ], [ 32, 33 ]] } } })3.3 redis
1 Geospatial commands
- geoadd
- geoadd key longitude latitude member [ longitude latitude member ... ]
- Add the specified space element to the specified key in
- geodist
- geodist key member1 member2 [ unit ]
- unit Representative unit
- Returns the distance between specified positions
- geohash
- geohash key member [ member ... ]
- Return to a standard geospatial geohash character string
- geopos
- geopos key member [ member ... ]
- Back to the latitude and longitude of geospatial
- georadius
- georadius key longitude latitude radius m|km|ft|mi [ WITHCOORD ] [ WITHDIST ] [ WITHHASH ] [ COUNT count ]
- Query the collection of all geospatial elements within the specified radius
- longitude longitude
- latitude latitude
- radius Radius distance number
- WITHDIST The distance between the centers of the position elements is also returned
- WITHCOORD Return the longitude and latitude of the location element as well
- WITHHASH With 52 Bit signed integer returns
- COUNT Before returning all matching positions count Elements
- georadiusbymember
- georadiusbymember key member radius m|km|ft|mi [ WITHCOORD ] [ WITHDIST ] [ WITHHASH ] [ COUNT count ]
- Query a geospatial element that matches the maximum distance within the specified radius
边栏推荐
- Basic introduction and source code analysis of webrtc threads
- NLP text processing: lemma [English] [put the deformation of various types of words into one form] [wet- > go; are- > be]
- 孤勇者
- [groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)
- MySQL storage engine
- 可恢复保险丝特性测试
- Atcoder beginer contest 254 [VP record]
- 云导DNS和知识科普以及课堂笔记
- Global and Chinese market of valve institutions 2022-2028: Research Report on technology, participants, trends, market size and share
- Calculate sha256 value of data or file based on crypto++
猜你喜欢
![[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte](/img/61/73becfc3b46669d31b0cf334aa54f2.jpg)
[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte

Search (DFS and BFS)
![[groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)](/img/e4/a41fe26efe389351780b322917d721.jpg)
[groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)

Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4

如何利用Flutter框架开发运行小程序

Introduction of motor
![[groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)](/img/d4/4a33e7f077db4d135c8f38d4af57fa.jpg)
[groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)

时间戳的拓展及应用实例

MCU通过UART实现OTA在线升级流程

The relationship between FPGA internal hardware structure and code
随机推荐
Go learning - dependency injection
剖面测量之提取剖面数据
[groovy] JSON string deserialization (use jsonslurper to deserialize JSON strings | construct related classes according to the map set)
详细页返回列表保留原来滚动条所在位置
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
[designmode] Decorator Pattern
Spark SQL null value, Nan judgment and processing
Global and Chinese markets for pressure and temperature sensors 2022-2028: Research Report on technology, participants, trends, market size and share
Spark AQE
Spark-SQL UDF函数
curlpost-php
云导DNS和知识科普以及课堂笔记
LeetCode 1598. Folder operation log collector
Idea remotely submits spark tasks to the yarn cluster
Room cannot create an SQLite connection to verify the queries
Leetcode 450 deleting nodes in a binary search tree
Atcoder beginer contest 254 [VP record]
关于slmgr命令的那些事
How to make your own robot
Notepad + + regular expression replace String