jazzband / geojson

Python bindings and utilities for GeoJSON
https://pypi.python.org/pypi/geojson/
BSD 3-Clause "New" or "Revised" License
898 stars 120 forks source link

Improve point validation #144

Closed Rumpelstinsk closed 4 years ago

Rumpelstinsk commented 4 years ago

When you initialize a point using coordinates for a line, it says is a valid point:

import geojson

lineCoords=[[1,2],[3,4]]
pointCoords=[5,6]

print ("Line(lineCoords): ", geojson.LineString(lineCoords).is_valid)
print ("Line(pointCoors): ", geojson.LineString(pointCoords).is_valid)
print ("Point(pointCoords): ", geojson.Point(pointCoords).is_valid)
print ("Point(lineCoords): ", geojson.Point(lineCoords).is_valid)

Which produces the next exit:

Line(lineCoords): True Line(pointCoors): False Point(pointCoords): True Point(lineCoords): True

The reason behind this, is because the position array is only validating it's length, but not the format.

I think this pull request solves the problem

codecov[bot] commented 4 years ago

Codecov Report

Merging #144 into master will decrease coverage by 0.51%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #144      +/-   ##
==========================================
- Coverage   94.78%   94.26%   -0.52%     
==========================================
  Files          10       10              
  Lines         345      349       +4     
  Branches       69       71       +2     
==========================================
+ Hits          327      329       +2     
- Misses         10       11       +1     
- Partials        8        9       +1     
Impacted Files Coverage Δ
geojson/geometry.py 100.00% <100.00%> (ø)
geojson/utils.py 84.76% <0.00%> (-1.91%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d1a47d5...522bdec. Read the comment docs.