Skip to content

Instantly share code, notes, and snippets.

@jatorre
Created September 11, 2012 22:39
Show Gist options
  • Save jatorre/3702691 to your computer and use it in GitHub Desktop.
Save jatorre/3702691 to your computer and use it in GitHub Desktop.
<?php
require("Encoding.php");
//Get IDs
$jsonurl = "http://lamp.sla.ny.gov/ArcGIS/rest/services/sla/MapServer/4/query?text=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=1%3D1&time=&returnIdsOnly=true&returnGeometry=true&maxAllowableOffset=&outSR=4326&outFields=OBJECTID%2CShape%2CSerialNo%2CLicenseType%2CLicenseClass%2CZone%2CCountyCode%2CName%2CDBA%2CAddress1%2CAddress2%2CCity%2CState%2CZIP%2CLicenseCat%2CLicenseSym&f=json";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);
$page= 950;
$fp = fopen('bodegas.csv', 'w');
$data = array("OBJECTID","SerialNo","LicenseType","LicenseClass","Zone","CountyCode","Name","DBA","Address1","Address2","City","State","ZIP","LicenseCat","LicenseSym","longitude","latitude");
fputcsv($fp, $data);
for ($i = 0; $i <= (end($json_output->objectIds)/$page); $i++) {
//Get the data
$jsonurl = "http://lamp.sla.ny.gov/ArcGIS/rest/services/sla/MapServer/4/query?text=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=OBJECTID%3C+".(($i+1)*$page)."+AND+OBJECTID%3E=+".($i*$page)."&time=&returnIdsOnly=false&returnGeometry=true&maxAllowableOffset=&outSR=4326&outFields=OBJECTID%2CShape%2CSerialNo%2CLicenseType%2CLicenseClass%2CZone%2CCountyCode%2CName%2CDBA%2CAddress1%2CAddress2%2CCity%2CState%2CZIP%2CLicenseCat%2CLicenseSym&f=json";
$json2 = file_get_contents($jsonurl,0,null,null);
$json_output2 = json_decode($json2);
echo("records:".($i*$page)."-".(($i+1)*$page)."\n");
foreach ( $json_output2->features as $feature ){
$name = Encoding::toLatin1($feature->attributes->Name);
if ($feature->attributes->Name != Encoding::toLatin1($feature->attributes->Name)) {
$name = "utf8 problem";
}
$DBA = Encoding::toLatin1($feature->attributes->DBA);
if ($feature->attributes->DBA != Encoding::toLatin1($feature->attributes->DBA)) {
$DBA = "utf8 problem";
}
$Address1 = $feature->attributes->Address1;
$Address2 = $feature->attributes->Address2;
$data = array($feature->attributes->OBJECTID,$feature->attributes->SerialNo,$feature->attributes->LicenseType,$feature->attributes->LicenseClass,$feature->attributes->Zone,$feature->attributes->CountyCode,$Name,$DBA,$Address1,$Address2,$feature->attributes->City,$feature->attributes->State,$feature->attributes->ZIP,$feature->attributes->LicenseCat,$feature->attributes->LicenseSym,$feature->geometry->x,$feature->geometry->y);
fputcsv($fp, $data);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment