1

I've uploaded a geojson file to my firebase realtime database and setup an http get request in my angular app to retrieve the data. Here's a small sample of my data. All it is is an array of objects. Each object is a zip code. Below are two zip code objects.

[
   {
      "type":"Feature",
      "properties":{
         "STATEFP10":"44",
         "ZCTA5CE10":"02818",
         "GEOID10":"4402818",
         "CLASSFP10":"B5",
         "MTFCC10":"G6350",
         "FUNCSTAT10":"S",
         "ALAND10":56516634,
         "AWATER10":8882294,
         "INTPTLAT10":"+41.6429192",
         "INTPTLON10":"-071.4857186",
         "PARTFLG10":"N"
      },
      "geometry":{
         "type":"Polygon",
         "coordinates":[
            [
               [
                  -71.457848,
                  41.672076
               ],
               [
                  -71.457848,
                  41.672414
               ],
               [
                  -71.457848,
                  41.672932
               ],
               [
                  -71.457916,
                  41.67407
               ]
            ]
         ]
      }
   },
   {
      "type":"Feature",
      "properties":{
         "STATEFP10":"44",
         "ZCTA5CE10":"02878",
         "GEOID10":"4402878",
         "CLASSFP10":"B5",
         "MTFCC10":"G6350",
         "FUNCSTAT10":"S",
         "ALAND10":75250623,
         "AWATER10":8363563,
         "INTPTLAT10":"+41.6101375",
         "INTPTLON10":"-071.1804709",
         "PARTFLG10":"N"
      },
      "geometry":{
         "type":"Polygon",
         "coordinates":[
            [
               [
                  -71.210351,
                  41.656166
               ],
               [
                  -71.209897,
                  41.657718
               ],
               [
                  -71.208399,
                  41.660013
               ],
               [
                  -71.20787,
                  41.661323
               ]
            ]
         ]
      }
   }
]

I can retrieve all of my data no problem but I can't seem to filter specific zip codes. I have read over the guides on firebase (https://firebase.google.com/docs/database/rest/retrieve-data) and can not get this to work with params. What I'm trying to do is filter an object based on the "ZCTA5CE10" value in "properties". I have tried many different combinations. Below is one of them:

getZipData() {
  return this.http.get(this.url + '?orderBy="properties/ZCTA5CE10"&equalTo="02818"');
} 

I get a 400 error when attempting to use params. What am I doing wrong?

Also, Is it possible to filter multiple zip codes E.g. &equalTo="02818"&equalTo="02878"

Kyle Abens
  • 243
  • 4
  • 18
  • What is the value of this.url? [And it is not possible to filter multiple zip codes](https://stackoverflow.com/q/26700924/4916627) – André Kool Apr 13 '18 at 08:53
  • Also your data does not look like valid firebase data because firebase doesnt support arrays in that way. – André Kool Apr 13 '18 at 08:54
  • My url is just the path to my Firebase database. I know Firebase converts arrays into key value pairs which is why it makes this a little tricky. I was able write a rule in Firebase that allowed me to orderBy the index of the index number assigned to each object in Firebase. I think I can map it correctly from here but is there a way to have multiple equalTo’s ? How can I retrieve 3 specific zip codes at once? – Kyle Abens Apr 13 '18 at 11:38
  • It looks like multiple equalTo's are not possible. Thanks for the help! – Kyle Abens Apr 13 '18 at 12:25
  • I imported your data and the query works for me: https://stackoverflow.firebaseio.com/49809560.json?orderBy="properties/ZCTA5CE10"&equalTo="02818"&print=pretty – Frank van Puffelen Apr 13 '18 at 14:04
  • Yea I got it working. Now I'm just trying to upload a very large json file to Firebase RTDB because firestore doesn't support an array of arrays which is needed for geojson. – Kyle Abens Apr 13 '18 at 17:45

0 Answers0