← back to Dandeana Hub

scripts/pull-parcels.js

59 lines

// Pulls the recorded tract's parcel records (owners, assessed values, deed refs)
// from San Diego County's public ARCC parcel layer into data/parcels.json. $0.
const fs = require('fs');
const path = require('path');

const LAYER = 'https://gis-public.sandiegocounty.gov/arcgis/rest/services/ARCC/apprmapr/MapServer/2/query';
const WHERE = "SUBNAME LIKE 'POWAY TCT NO 16-005%'";
const FIELDS = 'APN,OWN_NAME1,OWN_NAME2,LEGLDESC,ACREAGE,ASR_LAND,ASR_IMPR,ASR_TOTAL,DOCNMBR,DOCDATE,TAXSTAT,SITUS_ADDRESS,SITUS_STREET,SITUS_SUFFIX,TOTAL_LVG_AREA,BEDROOMS,BATHS';

function fmtDocDate(mmddyy) {
  if (!mmddyy || mmddyy.length !== 6) return null;
  const [mm, dd, yy] = [mmddyy.slice(0, 2), mmddyy.slice(2, 4), mmddyy.slice(4, 6)];
  return `20${yy}-${mm}-${dd}`;
}

async function pullParcels(DATA) {
  const url = `${LAYER}?where=${encodeURIComponent(WHERE)}&outFields=${FIELDS}&returnGeometry=false&orderByFields=APN&f=json`;
  const r = await fetch(url, { headers: { 'User-Agent': 'DandeanaHub/1.0' } });
  if (!r.ok) throw new Error(`county GIS HTTP ${r.status}`);
  const j = await r.json();
  if (j.error) throw new Error(`county GIS error: ${JSON.stringify(j.error)}`);
  const lots = (j.features || []).map(f => {
    const a = f.attributes;
    const lot = (a.LEGLDESC || '').replace(/\\.*/, '').trim();
    return {
      apn: a.APN.replace(/^(\d{3})(\d{3})(\d{2})(\d{2})$/, '$1-$2-$3-$4'),
      lot,
      owner: [a.OWN_NAME1, a.OWN_NAME2].filter(Boolean).join(' / ').trim(),
      acreage: a.ACREAGE,
      assessedLand: a.ASR_LAND,
      assessedImprovements: a.ASR_IMPR,
      assessedTotal: a.ASR_TOTAL || (a.ASR_LAND != null && a.ASR_IMPR != null ? a.ASR_LAND + a.ASR_IMPR : null),
      deedDoc: a.DOCNMBR ? `2024/2025 series doc #${a.DOCNMBR}` : null,
      deedDocNumber: a.DOCNMBR || null,
      deedDate: fmtDocDate(a.DOCDATE),
      address: a.SITUS_ADDRESS ? `${a.SITUS_ADDRESS} ${a.SITUS_STREET || ''} ${a.SITUS_SUFFIX || ''}`.replace(/\s+/g, ' ').trim() : null,
      livingArea: a.TOTAL_LVG_AREA || null,
      bedrooms: a.BEDROOMS ? parseInt(a.BEDROOMS, 10) : null,
      baths: a.BATHS ? parseInt(a.BATHS, 10) / 10 : null,
      taxable: a.TAXSTAT === 'T',
    };
  });
  const out = {
    pulledAt: new Date().toISOString(),
    source: 'San Diego County ARCC public parcel layer (gis-public.sandiegocounty.gov)',
    tract: 'POWAY TCT NO 16-005 (Larchmont St) — marketed as "Lyon Estates" by New Pointe Communities',
    lots,
  };
  fs.writeFileSync(path.join(DATA, 'parcels.json'), JSON.stringify(out, null, 2));
  console.log(`parcels: ${lots.length} lots written`);
  return out;
}

module.exports = { pullParcels };

if (require.main === module) {
  pullParcels(path.join(__dirname, '..', 'data')).catch(e => { console.error(e); process.exit(1); });
}