Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xplot_server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
digit_plot
xplot_server
Commits
503ff447
Commit
503ff447
authored
Nov 09, 2024
by
dliangx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
作业路线数据
parent
d1389484
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
11 deletions
+26
-11
geo/geojson_processor.go
+22
-7
geo/geojson_processor_test.go
+1
-1
sql/area.sql
+3
-3
No files found.
geo/geojson_processor.go
View file @
503ff447
...
@@ -50,13 +50,22 @@ func connectDB() (*sql.DB, error) {
...
@@ -50,13 +50,22 @@ func connectDB() (*sql.DB, error) {
}
}
func
createTable
(
db
*
sql
.
DB
)
error
{
func
createTable
(
db
*
sql
.
DB
)
error
{
// _, err := db.Exec(`
// CREATE TABLE IF NOT EXISTS geojson_data (
// id SERIAL PRIMARY KEY,
// type VARCHAR(64),
// geom geometry(Geometry,4326),
// properties JSONB
// )
// `)
_
,
err
:=
db
.
Exec
(
`
_
,
err
:=
db
.
Exec
(
`
CREATE TABLE IF NOT EXISTS geojson_data
(
create table IF NOT EXISTS opt_fly_routes
(
id
SERIAL PRIMARY KEY
,
id
serial PRIMARY key
,
type VARCHAR(64),
type VARCHAR(64),
geom geometry(Geometry,4326),
properties JSONB,
properties JSONB
opt_time timestamp,
)
geometry geometry(linestring,4326)
);
`
)
`
)
return
err
return
err
}
}
...
@@ -125,9 +134,15 @@ func processFile(filename string, db *sql.DB) error {
...
@@ -125,9 +134,15 @@ func processFile(filename string, db *sql.DB) error {
log
.
Printf
(
"转换properties失败: %v"
,
err
)
log
.
Printf
(
"转换properties失败: %v"
,
err
)
continue
continue
}
}
// _, err = tx.Exec(`
// INSERT INTO geojson_data (type, geom, properties)
// VALUES ($1, ST_GeomFromGeoJSON($2), $3)
// `, feature.Type, string(geometryJSON), string(propertiesJSON))
_
,
err
=
tx
.
Exec
(
`
_
,
err
=
tx
.
Exec
(
`
INSERT INTO
geojson_data (type, geom, properties
)
INSERT INTO
opt_fly_routes (type, geometry, properties,opt_time
)
VALUES ($1, ST_GeomFromGeoJSON($2), $3)
VALUES ($1, ST_GeomFromGeoJSON($2), $3
,now()
)
`
,
feature
.
Type
,
string
(
geometryJSON
),
string
(
propertiesJSON
))
`
,
feature
.
Type
,
string
(
geometryJSON
),
string
(
propertiesJSON
))
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"插入数据失败: %v"
,
err
)
log
.
Printf
(
"插入数据失败: %v"
,
err
)
...
...
geo/geojson_processor_test.go
View file @
503ff447
...
@@ -3,6 +3,6 @@ package geo
...
@@ -3,6 +3,6 @@ package geo
import
"testing"
import
"testing"
func
TestInitProcessFile
(
t
*
testing
.
T
)
{
func
TestInitProcessFile
(
t
*
testing
.
T
)
{
filename
:=
"/Users/liang/Downloads/
山西省村界
.geojson"
filename
:=
"/Users/liang/Downloads/
dji
.geojson"
ProcessGeoJSONFile
(
filename
)
ProcessGeoJSONFile
(
filename
)
}
}
sql/area.sql
View file @
503ff447
...
@@ -4,7 +4,7 @@ create table opt_routes (
...
@@ -4,7 +4,7 @@ create table opt_routes (
id
serial
PRIMARY
key
,
id
serial
PRIMARY
key
,
type
VARCHAR
(
64
),
type
VARCHAR
(
64
),
properties
JSONB
,
properties
JSONB
,
opt_time
date
,
opt_time
timestamp
,
geometry
geometry
(
linestring
,
4326
)
geometry
geometry
(
linestring
,
4326
)
);
);
...
@@ -13,7 +13,7 @@ create table opt_fly_routes (
...
@@ -13,7 +13,7 @@ create table opt_fly_routes (
id
serial
PRIMARY
key
,
id
serial
PRIMARY
key
,
type
VARCHAR
(
64
),
type
VARCHAR
(
64
),
properties
JSONB
,
properties
JSONB
,
opt_time
date
,
opt_time
timestamp
,
geometry
geometry
(
linestring
,
4326
)
geometry
geometry
(
linestring
,
4326
)
);
);
...
@@ -22,7 +22,7 @@ create table opt_area(
...
@@ -22,7 +22,7 @@ create table opt_area(
id
serial
PRIMARY
key
,
id
serial
PRIMARY
key
,
type
VARCHAR
(
64
),
type
VARCHAR
(
64
),
properties
JSONB
,
properties
JSONB
,
opt_time
date
,
opt_time
timestamp
,
geometry
geometry
(
polygon
,
4326
)
geometry
geometry
(
polygon
,
4326
)
);
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment