Skip to content

Commit

Permalink
Add WKT
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaskins committed Dec 31, 2024
1 parent 5d8d654 commit f89ad2e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
10 changes: 10 additions & 0 deletions spec/geo/coord_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ describe Geo::Coord do
geojson.should be_a(GeoJSON::Coordinates)
end

describe "#to_wkt" do
it "generates a Well Known Text format" do
coord = Geo::Coord.new(50.004444, 36.231389)

ewkt = coord.to_wkt

ewkt.should eq "POINT(36.231389 50.004444)"
end
end

describe "#to_ewkt" do
it "generates an Extended Well Known Text format" do
coord = Geo::Coord.new(50.004444, 36.231389)
Expand Down
15 changes: 12 additions & 3 deletions src/geo/coord.cr
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ module Geo
def to_ewkt(io : IO) : Nil
# SRID 4326 is used for latitude and longitude
# https://epsg.org/crs_4326/WGS-84.html
io << "SRID=4326;POINT("
io << lng << ' ' << lat
io << ')'
io << "SRID=4326;"
to_wkt io
end

def to_ewkb : Bytes
Expand All @@ -197,6 +196,16 @@ module Geo
bytes
end

def to_wkt : String
String.build { |str| to_wkt str }
end

def to_wkt(io : IO) : Nil
io << "POINT("
io << lng << ' ' << lat
io << ')'
end

def ll
{lat, lng}
end
Expand Down

0 comments on commit f89ad2e

Please sign in to comment.