Fix potential nullpointer around spatial index writer