# JuliaGeo: Combine 2 files with points into one and export to shapefile

**URL:** https://discourse.julialang.org/t/juliageo-combine-2-files-with-points-into-one-and-export-to-shapefile/124003
**Category:** New to Julia
**Tags:** question, geo
**Created:** [December 19, 2024, 11:50pm UTC](https://discourse.julialang.org/t/juliageo-combine-2-files-with-points-into-one-and-export-to-shapefile/124003 "2024-12-19T23:50:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![alecStewart1](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@alecStewart1](https://discourse.julialang.org/u/alecStewart1)
#### Post date: [December 19, 2024, 11:50pm UTC](https://discourse.julialang.org/t/juliageo-combine-2-files-with-points-into-one-and-export-to-shapefile/124003/1 "2024-12-19T23:50:15Z")

</div>

Hello friends,

I’ve been trying to combine 2 shapefiles that have point data.

I have put in an issue with GeoDataFrames [here](https://github.com/evetion/GeoDataFrames.jl/issues/99) but I’ll detail my issues here.

Initially I tried with a shapefile and a CSV file, but now I’ve tried with 2 shapefiles, one I created from finding the centroids of polygons and the other is form a different dataset:

```julia
import GeoDataFrames as GDF

centroid_df = GDF.read("/home/my-user/centroid.shp")
point_df = GDF.read("/home/my-user/point.shp")

combined_df = vcat(centroid_df, point_df, cols=:union)

```

This works great. _Now_ comes trying to turn this combined dataframe into a new shapefile.

```julia
# with code above

GDF.write("/home/my-user/combined.shp", combined_df)

```

Great. Now if I read this combined shapefile to check everything is okay, all of the felds that had Cyrillic or Mandarian characters in them have been transformed into `?????????`. If I write to a CSV file using GeoDataFrames, the same characters are now Latin-1 characters.

Okay, well, I can try using ArchGDAL to get the latitude and longitude of the Geometries in the GDF `geometry` column. The closest methods I can find are [`gety`](https://yeesian.com/ArchGDAL.jl/latest/reference/#ArchGDAL.gety-Tuple%7BArchGDAL.AbstractGeometry,%20Integer%7D) and [`getx`](https://yeesian.com/ArchGDAL.jl/latest/reference/#ArchGDAL.getx-Tuple%7BArchGDAL.AbstractGeometry,%20Integer%7D):

```julia
# Just to see if the one of the first items and later items are sane
# There's about 700,000 rows.

import ArchGDAL as AG

AG.getx(combined_df[!,:geometry][5], 0)
# -> 3.253345042199999e6

AG.gety(combined_df[!,:geometry][5], 0)
# -> 7.0101121679000035e6

AG.getx(combined_df[!,:geometry][600000], 0)
# -> -1.5517223299039526

AG.gety(combined_df[!,:geometry][600000], 0)
# -> 47.086016784843764

```

Hmm, okay. Unfortunately, these numbers don’t translate well to a CSV or Excel sheet.

```julia
using CSV

combined_df[!,:latitude] = collect(Iterators.map(pt -> AG.gety(pt, 0), combined_df[!,:geometry]))
combined_df[!,:longitude] = collect(Iterators.map(pt -> AG.getx(pt, 0), combined_df[!,:geometry]))

select!(combined_df, Not(:geometry))

CSV.write("/home/my-user/combined_points.csv", combined_df, bom=true)

```

So the characters are correct now, but now the some of the numbers are represented as `7.0101121679000035E+6` in the CSV file.

Any suggestions?

---

<div class="post-metadata">

### Author: ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)
#### Post date: [December 20, 2024, 6:11am UTC](https://discourse.julialang.org/t/juliageo-combine-2-files-with-points-into-one-and-export-to-shapefile/124003/2 "2024-12-20T06:11:59Z")

</div>

This looks like an issue with GDAL, specifically its treatment of character encodings in Shapefiles. I replied to the issue you filed with GeoDataFrames as well, but can you confirm that the Cyrillic/Mandarin strings in `centroid_df` and `point_df` are loaded correctly?

---

<div class="post-metadata">

### Author: ![alecStewart1](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@alecStewart1](https://discourse.julialang.org/u/alecStewart1)
#### Post date: [December 20, 2024, 3:03pm UTC](https://discourse.julialang.org/t/juliageo-combine-2-files-with-points-into-one-and-export-to-shapefile/124003/3 "2024-12-20T15:03:47Z")

</div>

Seems to:

```julia
import GeoDataFrames as GDF

centroid_df = GDF.read("/home/my-user/Downloads/FindCentroidsOutput.shp")

centroid_df[!,:name]

# A few of the Cyrillic names

586069-element Vector{Union{Missing, String}}:
 "Ленинградская"
 "Кустанайская"
 "Выборгская"
 "Кирилловская"

point_df = GDF.read("/home/my-user/Downloads/point.shp")

point_df[!,:name]

# a Cyrillic name from this dataframe

129943-element Vector{Union{Missing, String}}:
"КТП-130Г"

```

I’d have to figure out a way to grab some Cyrillic and Mandarin characters, as you can see there’s quite a bit of data in both. Let me try the example you gave on Github.

---

<div class="post-metadata">

### Author: ![alecStewart1](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@alecStewart1](https://discourse.julialang.org/u/alecStewart1)
#### Post date: [December 20, 2024, 3:24pm UTC](https://discourse.julialang.org/t/juliageo-combine-2-files-with-points-into-one-and-export-to-shapefile/124003/4 "2024-12-20T15:24:38Z")

</div>

Responded to your reply on my Github issue.

It seems like whatever `GeoDataFrames.write` uses for writing to a CSV file doesn’t allow for adding the UTF-8 BOM header, like `CSV.write` does.

> **[Writing · CSV.jl](https://csv.juliadata.org/stable/writing.html#CSV.write)**
>
> Documentation for CSV.jl.

I imagine this is similar for writing to shapefiles, with whatever is required to write strings as UTF-8 compatible for shapefiles.

---

<div class="post-metadata">

### Author: ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)
#### Post date: [December 24, 2024, 3:12am UTC](https://discourse.julialang.org/t/juliageo-combine-2-files-with-points-into-one-and-export-to-shapefile/124003/5 "2024-12-24T03:12:27Z")

</div>

Ah, yeah GeoDataFrames doesn’t use CSV.jl at all (though it may in the future)
