-
Notifications
You must be signed in to change notification settings - Fork 0
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
(refs #29) added fetch citygml url #32
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
711e42d
(refs #29) added fetch citygml url
tajimagrp 67bca94
fixed to use another api
tajimagrp fc1724c
Merge branch 'main' into feature/29/fetch_asset_url
tajimagrp 56514a8
(refs #29) added docs
tajimagrp 1cf021a
(refs #29) fixed bugs
tajimagrp b3437fb
(refs #29) added test
tajimagrp cea863a
(refs #29) added test
tajimagrp 7666470
(refs #29) added test
tajimagrp bb46380
(refs #29) added test
tajimagrp e711a23
(refs #29) fixed dependencies
tajimagrp 154b8c7
(refs #29) fixed dependencies
tajimagrp f1eab95
(refs #29) fixed dependencies
tajimagrp a0aae97
(refs #29) fixed mock dependencies
tajimagrp d4a62bb
(refs #29) fixed dependencies
tajimagrp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
plateauutils.citygmlfinder パッケージ | ||
====================================== | ||
|
||
plateauutils.citygmlfinder.from_reearth_cms モジュール | ||
-------------------------------------------------- | ||
|
||
.. automodule:: plateauutils.citygmlfinder.from_reearth_cms | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
# coding: utf-8 | ||
import reearthcmsapi | ||
from reearthcmsapi.apis.tags import items_project_api | ||
from reearthcmsapi.model.model import Model | ||
from reearthcmsapi.model.versioned_item import VersionedItem | ||
from reearthcmsapi.model.asset_embedding import AssetEmbedding | ||
import pprint | ||
import requests | ||
|
||
|
||
class NoArgsException(Exception): | ||
pass | ||
|
||
|
||
class NotFoundException(Exception): | ||
pass | ||
|
||
|
||
# query reearth cms via public api | ||
def public_query( | ||
endpoint: str = None, prefecture: str = None, city_name: str = None | ||
) -> str: | ||
"""Re:EarthのパブリックAPIを利用して都道府県、市町村名からCityGMLを取得する | ||
|
||
Parameters | ||
---------- | ||
endpoint : str | ||
APIのエンドポイント | ||
prefecture : str | ||
都道府県 | ||
city_name : str | ||
市町村 | ||
|
||
Returns | ||
------- | ||
str | ||
CityGMLのパス | ||
""" | ||
if endpoint == None or prefecture == None or city_name == None: | ||
raise NoArgsException | ||
res = None | ||
page = 1 | ||
hasMore = True | ||
while hasMore: | ||
response = requests.get(endpoint, params={"page": page}) | ||
if response.status_code == 200: | ||
obj = response.json() | ||
for item in obj["results"]: | ||
keys = item.keys() | ||
if "city_name" in keys and "prefecture" in keys: | ||
if ( | ||
item["city_name"] == city_name | ||
and item["prefecture"] == prefecture | ||
): | ||
res = item["citygml"]["url"] | ||
return res | ||
hasMore = obj["hasMore"] | ||
print(hasMore) | ||
if hasMore: | ||
page += 1 | ||
else: | ||
hasMore = False | ||
if res == None: | ||
raise NotFoundException | ||
|
||
|
||
# check prefecture and city from given private api result | ||
def _check_prefecture_city(items, prefecture, city): | ||
# search each items from given prefecture and city | ||
for item in items: | ||
pref_check = False | ||
city_check = False | ||
for keys in item["fields"]: | ||
# Since the items are an array, whether each item have certain column varies. | ||
# This makes typing difficult. | ||
# So the fields are stored in the form of an array of key-value. | ||
if keys["key"] == "prefecture": | ||
if keys["value"] == prefecture: | ||
pref_check = True | ||
elif keys["key"] == "city_name": | ||
if keys["value"] == city: | ||
city_check = True | ||
elif keys["key"] == "citygml": | ||
try: | ||
# Asset is one. So it is not stored in the way of key-value and access directry. | ||
# But if the key does not exist, it raises an error | ||
url = keys["value"]["url"] | ||
except Exception as e: | ||
url = "" | ||
if pref_check and city_check: | ||
return url | ||
return None | ||
|
||
|
||
# query reearth cms via private api | ||
def private_query( | ||
endpoint: str = None, | ||
access_token: str = None, | ||
project: str = None, | ||
model: str = None, | ||
prefecture: str = None, | ||
city_name: str = None, | ||
): | ||
"""Re:EarthのプライベートAPIを利用して都道府県、市町村名からCityGMLを取得する | ||
|
||
Parameters | ||
---------- | ||
endpoint : str | ||
APIのエンドポイント | ||
access_token : str | ||
APIのアクセストークン | ||
project : str | ||
プロジェクトのIDもしくはエイリアス | ||
model : str | ||
モデルのIDもしくはエイリアス | ||
prefecture : str | ||
都道府県 | ||
city_name : str | ||
市町村 | ||
|
||
Returns | ||
------- | ||
str | ||
CityGMLのパス | ||
""" | ||
configuration = reearthcmsapi.Configuration( | ||
host=endpoint, access_token=access_token | ||
) | ||
# Enter a context with an instance of the API client | ||
with reearthcmsapi.ApiClient(configuration) as api_client: | ||
# Create an instance of the API class | ||
api_instance = items_project_api.ItemsProjectApi(api_client) | ||
|
||
# example passing only optional values | ||
path_params = { | ||
"projectIdOrAlias": project, | ||
"modelIdOrKey": model, | ||
} | ||
page = 1 | ||
perPage = 50 | ||
totalCount = 0 | ||
query_params = { | ||
"sort": "createdAt", | ||
"dir": "desc", | ||
"page": page, | ||
"perPage": perPage, | ||
"ref": "latest", | ||
"asset": AssetEmbedding("all"), | ||
} | ||
try: | ||
# Returns a list of items. | ||
api_response = api_instance.item_filter_with_project( | ||
path_params=path_params, | ||
query_params=query_params, | ||
) | ||
items = api_response.body["items"] | ||
url = _check_prefecture_city(items, prefecture, city_name) | ||
if url != None: | ||
return url | ||
totalCount = api_response.body["totalCount"] | ||
except reearthcmsapi.ApiException as e: | ||
print("Exception when calling ItemsApi->item_filter: %s\n" % e) | ||
while (page * perPage) < totalCount: | ||
page += 1 | ||
query_params = { | ||
"sort": "createdAt", | ||
"dir": "desc", | ||
"page": page, | ||
"perPage": perPage, | ||
"ref": "latest", | ||
"asset": AssetEmbedding("all"), | ||
} | ||
try: | ||
# Returns a list of items. | ||
api_response = api_instance.item_filter_with_project( | ||
path_params=path_params, | ||
query_params=query_params, | ||
) | ||
items = api_response.body["items"] | ||
url = _check_prefecture_city(items, prefecture, city_name) | ||
if url != None: | ||
return url | ||
except reearthcmsapi.ApiException as e: | ||
print("Exception when calling ItemsApi->item_filter: %s\n" % e) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
missing reearthcmsapi==0.0.2 for dev-requirements.txt