Browse Source

Calcul des boîtes par CP

geojson
U-U001PRD\u992093 7 years ago
parent
commit
5650eca649
1 changed files with 14 additions and 27 deletions
  1. +14
    -27
      preparefiles.R

+ 14
- 27
preparefiles.R View File

@@ -31,34 +31,21 @@ communes <- unionSpatialPolygons(communes, communes$Codepos)
# Conversion geojson
communes %>% geojson_list -> geojson

geojson_write(geojson, file = "communes.json")
# Ajout centroides
geojson$features$geometry$coordinates %>%
map(function(feature)
# Ajout bounds
test <- geojson
test$features <- test$features[28] # 2 polys
geojson$features %>%
map(function(feat)
{
if (!is.list(feature))
feature <- list(feature)
feat$geometry$coordinates %>%
unlist(recursive = F) %>%
unlist(recursive = F) %>%
transpose %>%
map(unlist, recursive =F) %>%
map(range) -> feat$properties$bounds
feature %>%
map(function(polygon)
{
if(dim(polygon)[1] > 1)
polygon %>% apply(2, mean)
else
polygon[1,,] %>% apply(2, mean)
}) %>%
{
c(map_dbl(.,1) %>% mean,
map_dbl(.,2) %>% mean)
}
}) -> geojson$features$properties$centroids
feat
}) -> geojson$features

# Ajout id
geojson$features$id <- geojson$features$properties$Codepos

geojson$features <- lapply(geojson$features, function(feat)
{
feat$id <- feat$properties$Codepos
feat
})
geojson_write(geojson, file = "communes.json")

Loading…
Cancel
Save