当前位置:网站首页>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
边栏推荐
- Key structure of ffmpeg - avformatcontext
- Reading notes of the beauty of programming
- LeetCode 6004. Get operands of 0
- NLP text processing: lemma [English] [put the deformation of various types of words into one form] [wet- > go; are- > be]
- FPGA内部硬件结构与代码的关系
- [groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)
- Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
- 免费的聊天机器人API
- Room cannot create an SQLite connection to verify the queries
- The global and Chinese markets of dial indicator calipers 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

MYSQL GROUP_ The concat function realizes the content merging of the same ID
![[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

Folding and sinking sand -- weekly record of ETF

Spark SQL null value, Nan judgment and processing

小程序技术优势与产业互联网相结合的分析

Data analysis thinking analysis methods and business knowledge -- analysis methods (II)

OpenCV经典100题

MIT博士论文 | 使用神经符号学习的鲁棒可靠智能系统

AtCoder Beginner Contest 254【VP记录】

Notepad + + regular expression replace String
随机推荐
Global and Chinese markets for pressure and temperature sensors 2022-2028: Research Report on technology, participants, trends, market size and share
Room cannot create an SQLite connection to verify the queries
How to solve the problems caused by the import process of ecology9.0
小程序技术优势与产业互联网相结合的分析
Classical concurrency problem: the dining problem of philosophers
AtCoder Beginner Contest 258【比赛记录】
Opencv classic 100 questions
Extension and application of timestamp
建立时间和保持时间的模型分析
Yolov5、Pycharm、Anaconda环境安装
Comment faire votre propre robot
Codeforces round 804 (Div. 2) [competition record]
Global and Chinese markets for hinged watertight doors 2022-2028: Research Report on technology, participants, trends, market size and share
Promise
Priority queue (heap)
notepad++正則錶達式替換字符串
[groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
SAP Spartacus home 页面读取 product 数据的请求的 population 逻辑
电机的简介