Code Monkey home page Code Monkey logo

Comments (7)

snowman2 avatar snowman2 commented on June 2, 2024 1

Summary of options I have thought of:

Option 1: Use CRS.to_json #1361 (comment)

Option 2: Use encoder #1361 (comment)

import json
from pyproj import CRS

class PROJEncoder(json.JSONEncoder):
    def default(self, obj):
        try:
            return crs.to_json_dict()
        except AttributeError:
            pass 
        return super().default(obj)

crs = CRS.from_user_input("EPSG:3857")
json.dumps(crs, cls=PROJEncoder)

Option 3: Ask Python json library to support a class method like __json__ so encoders are not needed anymore (possibly with a PEP) and then update pyproj to support it....

from pyproj.

hobu avatar hobu commented on June 2, 2024 1

I suppose Option #3 has been asked many times and there's some good reason for not implementing something like it over the years.

Hopefully this ticket generates enough google juice for the next person and points them to use CRS.to_json(). I'm happy to close this if there's no action to be taken on the pyproj side.

from pyproj.

rouault avatar rouault commented on June 2, 2024

This should work as lossless i/o in all be the rarest/weirdest situations, right @rouault?

yes

from pyproj.

jjimenezshaw avatar jjimenezshaw commented on June 2, 2024

@hobu Can json.dumps(crs) work without passing an encoder in the cls parameter?

from pyproj.

meliber avatar meliber commented on June 2, 2024

The CRS has to_json and to_json_dict methods which can return JSON string or dict which is consistent with PROJJSON.

from pyproj.

djhoese avatar djhoese commented on June 2, 2024

The __json__ solution would need to be split into an encode and decode method, right?

from pyproj.

snowman2 avatar snowman2 commented on June 2, 2024

The __json__ solution would need to be split into an encode and decode method, right?

Possiblity. Only thinking about one-way to encode to JSON at the moment as I don't think some things round-trip easily.

from pyproj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.