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
f8941d1b
Commit
f8941d1b
authored
Nov 14, 2024
by
dliangx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
7bca95c7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
17 deletions
+35
-17
geo/area.go
+21
-3
geo/geojson_processor.go
+1
-1
handler/http_handler.go
+12
-12
main.go
+1
-1
No files found.
geo/area.go
View file @
f8941d1b
...
@@ -99,6 +99,15 @@ func SaveOptArea(optArea model.GeoJson) (model.OptArea, error) {
...
@@ -99,6 +99,15 @@ func SaveOptArea(optArea model.GeoJson) (model.OptArea, error) {
area
.
OptTime
=
time
.
Now
()
area
.
OptTime
=
time
.
Now
()
area
.
Geometry
=
optArea
.
Geometry
area
.
Geometry
=
optArea
.
Geometry
area
.
Properties
=
optArea
.
Properties
area
.
Properties
=
optArea
.
Properties
optArea
.
Opt
=
4
relatedArea
,
err
:=
GetRelatedAdmArea
(
optArea
)
if
err
==
nil
{
for
key
,
value
:=
range
relatedArea
[
0
]
.
Properties
{
area
.
Properties
[
key
]
=
value
}
}
return
area
,
nil
return
area
,
nil
}
}
...
@@ -187,6 +196,15 @@ func UpdateOptArea(optArea model.GeoJson) (model.OptArea, error) {
...
@@ -187,6 +196,15 @@ func UpdateOptArea(optArea model.GeoJson) (model.OptArea, error) {
area
.
OptTime
=
time
.
Now
()
area
.
OptTime
=
time
.
Now
()
area
.
Geometry
=
optArea
.
Geometry
area
.
Geometry
=
optArea
.
Geometry
area
.
Properties
=
optArea
.
Properties
area
.
Properties
=
optArea
.
Properties
optArea
.
Opt
=
4
relatedArea
,
err
:=
GetRelatedAdmArea
(
optArea
)
if
err
==
nil
{
for
key
,
value
:=
range
relatedArea
[
0
]
.
Properties
{
area
.
Properties
[
key
]
=
value
}
}
return
area
,
nil
return
area
,
nil
}
}
...
@@ -472,10 +490,10 @@ func CalcAreasCenter(ids []string, opt int) (float64, float64, error) {
...
@@ -472,10 +490,10 @@ func CalcAreasCenter(ids []string, opt int) (float64, float64, error) {
}
}
err
=
db
.
QueryRow
(
query
)
.
Scan
(
&
wktPoint
)
err
=
db
.
QueryRow
(
query
)
.
Scan
(
&
wktPoint
)
if
wktPoint
==
""
{
return
0
,
0
,
fmt
.
Errorf
(
"no areas found"
)
}
if
err
!=
nil
{
if
err
!=
nil
{
if
err
==
sql
.
ErrNoRows
{
return
0
,
0
,
fmt
.
Errorf
(
"no areas found"
)
}
return
0
,
0
,
fmt
.
Errorf
(
"calculate center failed: %w"
,
err
)
return
0
,
0
,
fmt
.
Errorf
(
"calculate center failed: %w"
,
err
)
}
}
...
...
geo/geojson_processor.go
View file @
f8941d1b
...
@@ -45,7 +45,7 @@ func ProcessGeoJSONFile(filename string) error {
...
@@ -45,7 +45,7 @@ func ProcessGeoJSONFile(filename string) error {
}
}
func
connectDB
()
(
*
sql
.
DB
,
error
)
{
func
connectDB
()
(
*
sql
.
DB
,
error
)
{
connStr
:=
"postgres://
liang
:postgres@localhost/xpolt?sslmode=disable"
connStr
:=
"postgres://
postgres
:postgres@localhost/xpolt?sslmode=disable"
return
sql
.
Open
(
"postgres"
,
connStr
)
return
sql
.
Open
(
"postgres"
,
connStr
)
}
}
...
...
handler/http_handler.go
View file @
f8941d1b
...
@@ -25,7 +25,7 @@ func SaveGeometry(ctx context.Context, c *app.RequestContext) {
...
@@ -25,7 +25,7 @@ func SaveGeometry(ctx context.Context, c *app.RequestContext) {
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10001
,
"message"
:
err
.
Error
()})
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10001
,
"message"
:
err
.
Error
()})
return
return
}
}
c
.
JSON
(
consts
.
StatusOK
,
resp
)
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
200
,
"data"
:
resp
}
)
return
return
}
else
if
req
.
Opt
==
3
{
}
else
if
req
.
Opt
==
3
{
resp
,
err
:=
geo
.
SaveOptArea
(
req
)
resp
,
err
:=
geo
.
SaveOptArea
(
req
)
...
@@ -33,7 +33,7 @@ func SaveGeometry(ctx context.Context, c *app.RequestContext) {
...
@@ -33,7 +33,7 @@ func SaveGeometry(ctx context.Context, c *app.RequestContext) {
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10002
,
"message"
:
err
.
Error
()})
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10002
,
"message"
:
err
.
Error
()})
return
return
}
}
c
.
JSON
(
consts
.
StatusOK
,
resp
)
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
200
,
"data"
:
resp
}
)
return
return
}
else
{
}
else
{
c
.
JSON
(
consts
.
StatusBadRequest
,
utils
.
H
{
"message"
:
"opt value is not allow"
})
c
.
JSON
(
consts
.
StatusBadRequest
,
utils
.
H
{
"message"
:
"opt value is not allow"
})
...
@@ -54,7 +54,7 @@ func UpdateGeometry(ctx context.Context, c *app.RequestContext) {
...
@@ -54,7 +54,7 @@ func UpdateGeometry(ctx context.Context, c *app.RequestContext) {
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10003
,
"message"
:
err
.
Error
()})
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10003
,
"message"
:
err
.
Error
()})
return
return
}
}
c
.
JSON
(
consts
.
StatusOK
,
resp
)
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
200
,
"data"
:
resp
}
)
return
return
}
else
if
req
.
Opt
==
3
{
}
else
if
req
.
Opt
==
3
{
resp
,
err
:=
geo
.
UpdateOptArea
(
req
)
resp
,
err
:=
geo
.
UpdateOptArea
(
req
)
...
@@ -62,7 +62,7 @@ func UpdateGeometry(ctx context.Context, c *app.RequestContext) {
...
@@ -62,7 +62,7 @@ func UpdateGeometry(ctx context.Context, c *app.RequestContext) {
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10004
,
"message"
:
err
.
Error
()})
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10004
,
"message"
:
err
.
Error
()})
return
return
}
}
c
.
JSON
(
consts
.
StatusOK
,
resp
)
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
200
,
"data"
:
resp
}
)
return
return
}
else
{
}
else
{
c
.
JSON
(
consts
.
StatusBadRequest
,
utils
.
H
{
"message"
:
"opt value is not allow"
})
c
.
JSON
(
consts
.
StatusBadRequest
,
utils
.
H
{
"message"
:
"opt value is not allow"
})
...
@@ -91,7 +91,7 @@ func GetGeometry(ctx context.Context, c *app.RequestContext) {
...
@@ -91,7 +91,7 @@ func GetGeometry(ctx context.Context, c *app.RequestContext) {
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10005
,
"message"
:
err
.
Error
()})
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10005
,
"message"
:
err
.
Error
()})
return
return
}
}
c
.
JSON
(
consts
.
StatusOK
,
resp
)
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
200
,
"data"
:
resp
}
)
return
return
}
else
if
opt
==
3
{
}
else
if
opt
==
3
{
resp
,
err
:=
geo
.
GetOptArea
(
id
,
opt
)
resp
,
err
:=
geo
.
GetOptArea
(
id
,
opt
)
...
@@ -99,7 +99,7 @@ func GetGeometry(ctx context.Context, c *app.RequestContext) {
...
@@ -99,7 +99,7 @@ func GetGeometry(ctx context.Context, c *app.RequestContext) {
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10006
,
"message"
:
err
.
Error
()})
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10006
,
"message"
:
err
.
Error
()})
return
return
}
}
c
.
JSON
(
consts
.
StatusOK
,
resp
)
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
200
,
"data"
:
resp
}
)
return
return
}
else
{
}
else
{
c
.
JSON
(
consts
.
StatusBadRequest
,
utils
.
H
{
"message"
:
"opt value is not allow"
})
c
.
JSON
(
consts
.
StatusBadRequest
,
utils
.
H
{
"message"
:
"opt value is not allow"
})
...
@@ -127,7 +127,7 @@ func DeleteGeometry(ctx context.Context, c *app.RequestContext) {
...
@@ -127,7 +127,7 @@ func DeleteGeometry(ctx context.Context, c *app.RequestContext) {
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10007
,
"message"
:
err
.
Error
()})
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10007
,
"message"
:
err
.
Error
()})
return
return
}
}
c
.
JSON
(
consts
.
StatusOK
,
resp
)
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
200
,
"data"
:
resp
}
)
return
return
}
else
if
opt
==
3
{
}
else
if
opt
==
3
{
resp
,
err
:=
geo
.
DeleteOptArea
(
id
,
opt
)
resp
,
err
:=
geo
.
DeleteOptArea
(
id
,
opt
)
...
@@ -135,7 +135,7 @@ func DeleteGeometry(ctx context.Context, c *app.RequestContext) {
...
@@ -135,7 +135,7 @@ func DeleteGeometry(ctx context.Context, c *app.RequestContext) {
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10008
,
"message"
:
err
.
Error
()})
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10008
,
"message"
:
err
.
Error
()})
return
return
}
}
c
.
JSON
(
consts
.
StatusOK
,
resp
)
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
200
,
"data"
:
resp
}
)
return
return
}
else
{
}
else
{
c
.
JSON
(
consts
.
StatusBadRequest
,
utils
.
H
{
"message"
:
"opt value is not allow"
})
c
.
JSON
(
consts
.
StatusBadRequest
,
utils
.
H
{
"message"
:
"opt value is not allow"
})
...
@@ -155,7 +155,7 @@ func FindRelatedGeometry(ctx context.Context, c *app.RequestContext) {
...
@@ -155,7 +155,7 @@ func FindRelatedGeometry(ctx context.Context, c *app.RequestContext) {
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10009
,
"message"
:
err
.
Error
()})
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10009
,
"message"
:
err
.
Error
()})
return
return
}
}
c
.
JSON
(
consts
.
StatusOK
,
resp
)
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
200
,
"data"
:
resp
}
)
return
return
}
else
if
req
.
Opt
==
3
{
}
else
if
req
.
Opt
==
3
{
resp
,
err
:=
geo
.
GetRelatedOptArea
(
req
)
resp
,
err
:=
geo
.
GetRelatedOptArea
(
req
)
...
@@ -163,7 +163,7 @@ func FindRelatedGeometry(ctx context.Context, c *app.RequestContext) {
...
@@ -163,7 +163,7 @@ func FindRelatedGeometry(ctx context.Context, c *app.RequestContext) {
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10010
,
"message"
:
err
.
Error
()})
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10010
,
"message"
:
err
.
Error
()})
return
return
}
}
c
.
JSON
(
consts
.
StatusOK
,
resp
)
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
200
,
"data"
:
resp
}
)
return
return
}
else
if
req
.
Opt
==
4
{
}
else
if
req
.
Opt
==
4
{
resp
,
err
:=
geo
.
GetRelatedAdmArea
(
req
)
resp
,
err
:=
geo
.
GetRelatedAdmArea
(
req
)
...
@@ -171,7 +171,7 @@ func FindRelatedGeometry(ctx context.Context, c *app.RequestContext) {
...
@@ -171,7 +171,7 @@ func FindRelatedGeometry(ctx context.Context, c *app.RequestContext) {
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10010
,
"message"
:
err
.
Error
()})
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10010
,
"message"
:
err
.
Error
()})
return
return
}
}
c
.
JSON
(
consts
.
StatusOK
,
resp
)
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
200
,
"data"
:
resp
}
)
return
return
}
else
{
}
else
{
c
.
JSON
(
consts
.
StatusBadRequest
,
utils
.
H
{
"message"
:
"opt value is not allow"
})
c
.
JSON
(
consts
.
StatusBadRequest
,
utils
.
H
{
"message"
:
"opt value is not allow"
})
...
@@ -231,6 +231,6 @@ func CheckTwoOptAreaIsCross(ctx context.Context, c *app.RequestContext) {
...
@@ -231,6 +231,6 @@ func CheckTwoOptAreaIsCross(ctx context.Context, c *app.RequestContext) {
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10011
,
"message"
:
err
.
Error
()})
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
10011
,
"message"
:
err
.
Error
()})
return
return
}
}
c
.
JSON
(
consts
.
StatusOK
,
res
)
c
.
JSON
(
consts
.
StatusOK
,
utils
.
H
{
"code"
:
200
,
"data"
:
res
}
)
}
}
main.go
View file @
f8941d1b
...
@@ -13,8 +13,8 @@ import (
...
@@ -13,8 +13,8 @@ import (
)
)
func
main
()
{
func
main
()
{
//filename := "/Users/liang/Downloads/山西省村界.geojson"
// geo.ProcessGeoJSONFile(filename)
// geo.ProcessGeoJSONFile(filename)
//filename := "/Users/liang/Downloads/山西省村界.geojson"
h
:=
server
.
Default
(
h
:=
server
.
Default
(
server
.
WithHostPorts
(
":8686"
),
server
.
WithHostPorts
(
":8686"
),
)
)
...
...
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