当前位置:网站首页>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
边栏推荐
- Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
- OpenCV经典100题
- Power query data format conversion, Split Merge extraction, delete duplicates, delete errors, transpose and reverse, perspective and reverse perspective
- 【线上小工具】开发过程中会用到的线上小工具合集
- curlpost-php
- Basic introduction and source code analysis of webrtc threads
- The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
- Promise
- Idea remotely submits spark tasks to the yarn cluster
- [groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)
猜你喜欢
Atcoder beginer contest 254 [VP record]
如何解决ecology9.0执行导入流程流程产生的问题
Extracting profile data from profile measurement
esxi的安装和使用
notepad++正则表达式替换字符串
How to solve the problems caused by the import process of ecology9.0
SAP Spartacus home 页面读取 product 数据的请求的 population 逻辑
[groovy] JSON string deserialization (use jsonslurper to deserialize JSON strings | construct related classes according to the map set)
Model analysis of establishment time and holding time
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
随机推荐
MIT博士论文 | 使用神经符号学习的鲁棒可靠智能系统
[Online gadgets] a collection of online gadgets that will be used in the development process
Spark-SQL UDF函数
The global and Chinese markets of dial indicator calipers 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode 6005. The minimum operand to make an array an alternating array
How to make your own robot
建立时间和保持时间的模型分析
Reading notes of the beauty of programming
MySQL storage engine
uniapp开发,打包成H5部署到服务器
常用API类及异常体系
LeetCode 6004. Get operands of 0
Spark DF增加一列
可恢复保险丝特性测试
Ffmpeg captures RTSP images for image analysis
从 1.5 开始搭建一个微服务框架——调用链追踪 traceId
SQLServer连接数据库读取中文乱码问题解决
Calculate sha256 value of data or file based on crypto++
The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
Spark SQL空值Null,NaN判断和处理