Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Habitat Sampler
HabitatSampler
Commits
1ce61d1a
Commit
1ce61d1a
authored
Jul 09, 2021
by
Romulo Pereira Goncalves
Browse files
Merge branch 'master' into issue#13
parents
54c41204
c2f076b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
R-package/R/save_files.r
View file @
1ce61d1a
...
...
@@ -107,10 +107,14 @@ saveSamplePoints <-
}
result
<-
do.call
(
rbind
,
collect
)
res
<-
raster
::
extract
(
dummy_raster
,
result
)
if
(
length
(
which
(
is.na
(
res
)))
>
0
)
{
result
<-
result
[
-
which
(
is.na
(
res
)),
]
if
(
!
is.null
(
result
))
{
res
<-
raster
::
extract
(
dummy_raster
,
result
)
if
(
length
(
which
(
is.na
(
res
)))
>
0
)
{
result
<-
result
[
-
which
(
is.na
(
res
)),
]
}
}
else
{
result
<-
sp
::
SpatialPolygonsDataFrame
(
Sr
=
sp
::
SpatialPolygons
(
list
()),
data
=
data.frame
())
}
raster
::
crs
(
result
)
<-
raster
::
crs
(
dummy_raster
)
...
...
@@ -120,22 +124,22 @@ saveSamplePoints <-
if
(
nrow
(
result
)
>
0
)
{
result
<-
sp
::
spTransform
(
result
,
sp
::
CRS
(
"+init=epsg:4326"
))
}
rgdal
::
write
OGR
(
obj
=
result
,
sf
::
st_
write
(
obj
=
sf
::
st_as_sf
(
x
=
result
,
crs
=
4326
)
,
layer
=
paste
(
"SamplePoints_step_"
,
step
,
"_"
,
class_name
,
sep
=
""
),
dsn
=
paste
(
in_path
,
"SamplePoints_step_"
,
step
,
"_"
,
class_name
,
".geojson"
,
sep
=
""
),
driver
=
"GeoJSON"
,
check_exists
=
TRUE
,
overwrite_layer
=
TRU
E
append
=
FALS
E
)
}
else
{
rgdal
::
write
OGR
(
obj
=
result
,
sf
::
st_
write
(
obj
=
sf
::
st_as_sf
(
x
=
result
,
crs
=
4326
)
,
layer
=
paste
(
"SamplePoints_step_"
,
step
,
"_"
,
class_name
,
sep
=
""
),
dsn
=
paste
(
in_path
,
"SamplePoints_step_"
,
step
,
"_"
,
class_name
,
".shp"
,
sep
=
""
),
driver
=
"ESRI Shapefile"
,
check_exists
=
TRUE
,
overwrite_layer
=
TRU
E
append
=
FALS
E
)
}
}
...
...
@@ -193,10 +197,14 @@ writeOutSamples <- function(in_path, step, class_name, output_format = c("shp",
}
result
<-
do.call
(
rbind
,
collect
)
res
<-
raster
::
extract
(
dummy_sample
,
result
)
if
(
length
(
which
(
is.na
(
res
)))
>
0
)
{
result
<-
result
[
-
which
(
is.na
(
res
)),
]
if
(
!
is.null
(
result
))
{
res
<-
raster
::
extract
(
dummy_sample
,
result
)
if
(
length
(
which
(
is.na
(
res
)))
>
0
)
{
result
<-
result
[
-
which
(
is.na
(
res
)),
]
}
}
else
{
result
<-
sp
::
SpatialPolygonsDataFrame
(
Sr
=
sp
::
SpatialPolygons
(
list
()),
data
=
data.frame
())
}
raster
::
crs
(
result
)
<-
raster
::
crs
(
dummy_sample
)
output_format
<-
match.arg
(
output_format
)
...
...
@@ -205,22 +213,22 @@ writeOutSamples <- function(in_path, step, class_name, output_format = c("shp",
if
(
nrow
(
result
)
>
0
)
{
result
<-
sp
::
spTransform
(
result
,
sp
::
CRS
(
"+init=epsg:4326"
))
}
rgdal
::
write
OGR
(
obj
=
result
,
layer
=
paste
(
"
sel_SamplePoints_step_"
,
step
,
"
_"
,
class_name
,
sep
=
""
),
dsn
=
paste
(
in_path
,
"
sel_SamplePoints_step_"
,
step
,
"
_"
,
class_name
,
".geojson"
,
sep
=
""
),
sf
::
st_
write
(
obj
=
sf
::
st_as_sf
(
x
=
result
,
crs
=
4326
)
,
layer
=
paste
(
"
RefHaSa
_"
,
class_name
,
"_"
,
step
,
sep
=
""
),
dsn
=
paste
(
in_path
,
"
RefHaSa
_"
,
class_name
,
"_"
,
step
,
".geojson"
,
sep
=
""
),
driver
=
"GeoJSON"
,
check_exists
=
TRUE
,
overwrite_layer
=
TRU
E
append
=
FALS
E
)
}
else
{
rgdal
::
write
OGR
(
obj
=
result
,
layer
=
paste
(
"
sel_SamplePoints_step_"
,
step
,
"
_"
,
class_name
,
sep
=
""
),
dsn
=
paste
(
in_path
,
"
sel_SamplePoints_step_"
,
step
,
"
_"
,
class_name
,
".shp"
,
sep
=
""
),
sf
::
st_
write
(
obj
=
sf
::
st_as_sf
(
x
=
result
,
crs
=
4326
)
,
layer
=
paste
(
"
RefHaSa
_"
,
class_name
,
"_"
,
step
,
sep
=
""
),
dsn
=
paste
(
in_path
,
"
RefHaSa
_"
,
class_name
,
"_"
,
step
,
".shp"
,
sep
=
""
),
driver
=
"ESRI Shapefile"
,
check_exists
=
TRUE
,
overwrite_layer
=
TRU
E
append
=
FALS
E
)
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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