Eric Lemoine wrote: > If the encoder converts to str/unicode, then we'll end up with strings > in the GeoJSON.
Isn't JSON all text anyway? Indeed, the reason that a decimal.Decimal can not be automatically generated from a float is that it's unclear which decimal value you'd want: >> f = 0.1 >> repr(f) '0.10000000000000001' that's the as-exact-as-it-needs-to-be-to-assure-the-same binary-value-in-memory answer: >> str(f) '0.1' that's the rounded-to-a-reasonable-amount value. In this case, it's pretty obvious, but remember that python is designed around the philosophy of "refusing the temptation to guess" > But I don't know whether the decimal to float conversion is lossless? > Definitely something I need to consider... No, it's not. There are decimal numbers that can not be exactly represented as floating point, and the decimal module allows you to set precision well higher than floats. That being said, for practical purposes, with geo-coordinates, I doubt there will be issues. >> Assuming it can be arranged such that decimals in input GeoJOSN get >> encoded correctly with geojson.dump(s), As the code must be going from floats to strings anyway, having a method to go from Decimal to string makes sense. How is geojson.dumps() doing the float->string conversion now? The string formating operations should work the same way with Decimals as floats. >> and are returned as decimals in the result of geojson.load(s) so how do you indicate whether you want Decimals or floats? the JSON spec has only one type of number: http://www.ietf.org/rfc/rfc4627.txt?number=4627 Interestingly (to a geek like me, anyway) it doesn't even specify that numbers are expressed in base 10, but I think it's fair to assume that. - Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception _______________________________________________ Community mailing list [email protected] http://lists.gispython.org/mailman/listinfo/community
