0

Descendants and Children filtered by popRank

Hi to everybody,
I'm using the APIs through YQL and I'm having some trouble in retrieving the children of a Region/State filtered by type and popRank.
The main purpose is to retrieve all the cities of for example Europe that has popRank >= 11. I starts the cycle retrieving all the children of Europe (Countries) using :
CODE
select woeid,placeTypeName,name from geo.places.children where parent_woeid='24865675' and placetype='12'

I retrieves all countries of Europe, then I cycle inside each country to retrieve their main admin divions using this:
CODE
select woeid,placeTypeName,name from geo.places.children where parent_woeid='WOEID of each country' and placetype='8'


Finally the problem comes using this for retrieving all cities inside each admin divions:
CODE
select woeid from geo.places.children where parent_woeid='7153344' and placetype='7'

In the above query I'm trying to retrieve all the cities of Sicily (Italian region) but I have no results neighter errors.
So I decided to use Descendants:
CODE
[select woeid from geo.places.descendants where ancestor_woeid='7153344' and placetype='7'
and it seems to work, I really don't understand this inconsistency using Descendant or Children API!

Still my purpose is retrieve all cities with popRank >= "11".
Since is not possible to apply this filter as a parameter of Descendant API I tried this:
CODE
 select woeid,placeTypeName,name,popRank from geo.places where woeid in (select woeid from geo.places.descendants(10000) where ancestor_woeid='7153344' and placetype='7' )  and popRank>='11'


But this results depends mainly of the remote limits of the number of results returned by the inner query (10.000). I just discovered the max number of results from the GeoPlanet is 2000 (right?) so even though i put 10.000 I will never have a real result cause the inner query just scans ALL the cities children of a Region and the local filter popRank>='11' is applied later!

So the results depends on the number of cities for each regions: if they are <=2000 I will have real results otherwise I will have a false positive.

Any workaround, advise, tips to avoid to scans ALL the cities and then apply later the local filter (popRank) ?
Thanks and sorry for the long post!
Bye bye

by
6 Replies
  • QUOTE (Groob @ Nov 12 2010, 09:00 AM) <{POST_SNAPBACK}>
    Hi to everybody,
    I'm using the APIs through YQL and I'm having some trouble in retrieving the children of a Region/State filtered by type and popRank.
    The main purpose is to retrieve all the cities of for example Europe that has popRank >= 11. I starts the cycle retrieving all the children of Europe (Countries) using :
    CODE
    select woeid,placeTypeName,name from geo.places.children where parent_woeid='24865675' and placetype='12'

    I retrieves all countries of Europe, then I cycle inside each country to retrieve their main admin divions using this:
    CODE
    select woeid,placeTypeName,name from geo.places.children where parent_woeid='WOEID of each country' and placetype='8'


    Finally the problem comes using this for retrieving all cities inside each admin divions:
    CODE
    select woeid from geo.places.children where parent_woeid='7153344' and placetype='7'

    In the above query I'm trying to retrieve all the cities of Sicily (Italian region) but I have no results neighter errors.
    So I decided to use Descendants:
    CODE
    [select woeid from geo.places.descendants where ancestor_woeid='7153344' and placetype='7'
    and it seems to work, I really don't understand this inconsistency using Descendant or Children API!

    Still my purpose is retrieve all cities with popRank >= "11".
    Since is not possible to apply this filter as a parameter of Descendant API I tried this:
    CODE
     select woeid,placeTypeName,name,popRank from geo.places where woeid in (select woeid from geo.places.descendants(10000) where ancestor_woeid='7153344' and placetype='7' )  and popRank>='11'


    But this results depends mainly of the remote limits of the number of results returned by the inner query (10.000). I just discovered the max number of results from the GeoPlanet is 2000 (right?) so even though i put 10.000 I will never have a real result cause the inner query just scans ALL the cities children of a Region and the local filter popRank>='11' is applied later!

    So the results depends on the number of cities for each regions: if they are <=2000 I will have real results otherwise I will have a false positive.

    Any workaround, advise, tips to avoid to scans ALL the cities and then apply later the local filter (popRank) ?
    Thanks and sorry for the long post!
    Bye bye


    The descendants table is the correct one to use to find towns within a state, but you need to include "and view='long'" in your query in order to filter by popRank. as only woeid, name, and placeTypeName are returned by default for the descendants table. Here is an example YQL query that will return all large cities in Sicily:

    CODE
    select woeid, name, popRank from geo.places.descendants where ancestor_woeid='7153344' and placetype='7' and view='long' and popRank >= 11


    You can also use the geo.countries table for getting a list of country woeids within a continent like Europe:

    CODE
    select woeid from geo.countries where place='europe'


    You can get a list of top-level administrative areas for all European countries with the following query:

    CODE
    select woeid from geo.states where place in (select woeid from geo.countries where place='europe')

    This will produce 1100 woeids, so it would not be a good idea to use this as a subselect for the town search.

    Eddie Babcock
    Yahoo! Geo Technologies
    0
  • QUOTE (Eddie B @ Nov 12 2010, 02:55 PM) <{POST_SNAPBACK}>
    The descendants table is the correct one to use to find towns within a state, but you need to include "and view='long'" in your query in order to filter by popRank. as only woeid, name, and placeTypeName are returned by default for the descendants table. Here is an example YQL query that will return all large cities in Sicily:

    CODE
    select woeid, name, popRank from geo.places.descendants where ancestor_woeid='7153344' and placetype='7' and view='long' and popRank >= 11


    Thanks a lot!
    Btw in the meanwhile of my experiments I found that the children of the region "Lombardia" of Italy, WOEID="7153338" is not found, you can try it out from the YQL console: YQL Descendats of Lombardia
    I guess it is a temporary problem

    Bye
    0
  • QUOTE (Groob @ Nov 12 2010, 06:32 PM) <{POST_SNAPBACK}>
    I found that the children of the region "Lombardia" of Italy, WOEID="7153338" is not found, you can try it out from the YQL console: YQL Descendats of Lombardia
    I guess it is a temporary problem


    Still not working :( What happened to that region?
    0
  • QUOTE (Groob @ Nov 14 2010, 02:23 PM) <{POST_SNAPBACK}>
    Still not working :(Yahoo! Geo Technologies
    0
  • QUOTE (Eddie B @ Nov 15 2010, 02:55 PM) <{POST_SNAPBACK}>
    Lombardia has over 6,000 descendant towns so your query will not return any results. the Province of Pavia alone has 1,400 towns.

    Thanks for the reply, I have already asked in another post (with no answer) if there is a way to know the number in adavance, a sort of "count" statement of the sql syntax.
    Even I'm not interested in the data is it possible to know only the numbers of results either using Geo.Planet or Yql ?
    QUOTE
    You will need to go another level deeper in order to ensure that results can be returned. If you get no results for a state WOEID with a YQL query on the descendants table, you can iterate over the list of administrative children of the state. You can get this list using the geo.counties table:

    CODE
    select woeid from geo.counties where place=7153338
    This returns the WOEIDs for the provinces of Lombardia.

    Please note that some countries, such as Monaco and Andorra, do not have second-level administrative areas. Also, you do not need to enclose numbers, like WOEIDs and placetypes, in quotes within YQL queries.

    Does exit a way to know if a place have children of a particular type? Example in pseudocode
    CODE
    if (Lombardia has children of type county)   retrieve(Lombardia.Counties);
    Else retrieve(Lombardia.Cities);


    Thanks again, bye
    0
  • QUOTE (Groob @ Nov 16 2010, 03:38 AM) <{POST_SNAPBACK}>
    Thanks for the reply, I have already asked in another post (with no answer) if there is a way to know the number in adavance, a sort of "count" statement of the sql syntax.
    Even I'm not interested in the data is it possible to know only the numbers of results either using Geo.Planet or Yql ?

    Does exit a way to know if a place have children of a particular type? Example in pseudocode
    CODE
    if (Lombardia has children of type county)   retrieve(Lombardia.Counties);
    Else retrieve(Lombardia.Cities);


    Thanks again, bye


    YQL does not offer a count feature, but it sets the yahoo:count attribute in the query element to the number of rows that are returned. GeoPlanet sets the yahoo:total attribute in the places element to the total number of eligible results that can be returned. You can set the count parameter to 1 to return the minimal response that contains this data. If there are no eligible results, or too many eligible results, a 404 response will be returned; there is no way to distinguish between these conditions.

    You can use yahoo:count to determine if there are any children of a place when using YQL A value of 0 indicates there are no children, or too many children, of a place. You can append "limit 1" to your query to return the minimal response that contains this data. In GeoPlanet, a 404 response will be returned if there are no children, or too many children, of a place.

    Eddie Babcock
    Yahoo! Geo Technologies
    0
This forum is locked.

Recent Posts

in GeoPlanet General Discussion