-
Notifications
You must be signed in to change notification settings - Fork 43
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
feat: add geo accessor to Series #644
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright (c) 2013-2022, GeoPandas developers. | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
* Neither the name of GeoPandas nor the names of its contributors may | ||
be used to endorse or promote products derived from this software without | ||
specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import geopandas as gpd | ||
|
||
|
||
class GeoSeries(gpd.GeoSeries): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of subclassing geopandas.GeoSeries, subclass your new third_party version of it. |
||
def distance(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we discussed in chat, let's do Also, let's do a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved on new PR today. |
||
|
||
return self.distance(...) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from bigframes import constants | ||
|
||
if TYPE_CHECKING: | ||
import bigframes.series | ||
|
||
|
||
class GeoSeries: | ||
""" | ||
A Series object designed to store shapely geometry objects. | ||
""" | ||
|
||
@property | ||
def x(self) -> bigframes.series.Series: | ||
"""Return the x location of point geometries in a GeoSeries | ||
|
||
**Examples:** | ||
|
||
>>> import bigframes.pandas as bpd | ||
>>> bpd.options.display.progress_bar = None | ||
>>> from shapely.geometry import Point | ||
>>> import geopandas | ||
|
||
>>> series = bigframes.pandas.Series( | ||
... [shapely.Point(1, 1), shapely.Point(2, 2), shapely.Point(3, 3)], | ||
... dtype=geopandas.array.GeometryDtype() | ||
... ) | ||
>>> s.x | ||
0 1.0 | ||
1 2.0 | ||
2 3.0 | ||
dtype: float64 | ||
|
||
Returns: | ||
bigframes.series.Series: | ||
Return the x location (longitude) of point geometries. | ||
""" | ||
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) | ||
|
||
@property | ||
def y(self) -> bigframes.series.Series: | ||
"""Return the y location of point geometries in a GeoSeries | ||
|
||
**Examples:** | ||
|
||
>>> import bigframes.pandas as bpd | ||
>>> bpd.options.display.progress_bar = None | ||
>>> from shapely.geometry import Point | ||
>>> import geopandas | ||
|
||
>>> series = bigframes.pandas.Series( | ||
... [shapely.Point(1, 1), shapely.Point(2, 2), shapely.Point(3, 3)], | ||
... dtype=geopandas.array.GeometryDtype() | ||
... ) | ||
>>> s.y | ||
0 1.0 | ||
1 2.0 | ||
2 3.0 | ||
dtype: float64 | ||
|
||
Returns: | ||
bigframes.series.Series: | ||
Return the y location (latitude) of point geometries. | ||
""" | ||
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in
third_party
.