Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError on topojson.topology() #1

Closed
kbrose opened this issue Feb 15, 2019 · 3 comments
Closed

UnboundLocalError on topojson.topology() #1

kbrose opened this issue Feb 15, 2019 · 3 comments

Comments

@kbrose
Copy link

kbrose commented Feb 15, 2019

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-15-79e7f2268527> in <module>
----> 1 topojson.topology(zdf.head(2))

~.../lib/python3.6/site-packages/topojson/topology.py in topology(data, snap_vertices, gridsize_to_snap)
     28         data = joiner.main(data, quant_factor=None)
     29     data = cutter.main(data)
---> 30     data = deduper.main(data)
     31     data = hashmapper.main(data)
     32 

~.../lib/python3.6/site-packages/topojson/dedup.py in main(self, data)
    181         del data["bookkeeping_linestrings"]
    182         data["bookkeeping_arcs"] = self.list_from_array(array_bk)
--> 183         data["bookkeeping_shared_arcs"] = array_bk_sarcs.astype(int).tolist()
    184         data["bookkeeping_duplicates"] = self.list_from_array(
    185             data["bookkeeping_duplicates"][dup_pair_list != -99]

UnboundLocalError: local variable 'array_bk_sarcs' referenced before assignment
@mattijn
Copy link
Owner

mattijn commented Feb 15, 2019

Thanks for the first issue on this repo! Glad you give it a try.
Looking to the code you share it seems you do

topojson.topology(zdf.head(2))

Try remove the .head(2), or use zdf.iloc[0:2,:]

@kbrose
Copy link
Author

kbrose commented Feb 15, 2019

That doesn't change anything. The problem is that the array_bk_sarcs variable is created within an if block only, so if that if condition is not True then you will hit this error.

From within dedup.py:

    def main(self, data):
        # <removed docstring for clarity>

        # deduplicate equal geometries
        # create numpy array from bookkeeping_geoms variable for numerical computation
        array_bk = self.index_array(data["bookkeeping_linestrings"])
        if data["bookkeeping_duplicates"].size != 0:
            array_bk_sarcs, dup_pair_list = self.deduplicate(
                data["bookkeeping_duplicates"], data["linestrings"], array_bk
            )

        # <removed comment block for clarity>

        # prepare to return object
        del data["bookkeeping_linestrings"]
        data["bookkeeping_arcs"] = self.list_from_array(array_bk)
        data["bookkeeping_shared_arcs"] = array_bk_sarcs.astype(int).tolist()
        data["bookkeeping_duplicates"] = self.list_from_array(
            data["bookkeeping_duplicates"][dup_pair_list != -99]
        )

        return data

As you can see, the end of main() expects array_bk_sarcs to ALWAYS exist, but the variable is only created when data["bookkeeping_duplicates"].size != 0.

@mattijn
Copy link
Owner

mattijn commented Feb 17, 2019

Thanks for your clarification. You are right. This happened when trying to compute a topology between geometries without any shared boundaries.

All tests in the phase of deduplication (dedup.py) only included geometries that actually had duplicate boundaries. Solved via c9647cc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants