A method for determining the number and spatial locations of a plurality of target molecules in a sample, comprising: stochastically barcoding the plurality of target molecules in the sample using a plurality of stochastic barcodes, wherein each of the plurality of stochastic barcodes comprises a spatial label and a molecular label, wherein the spatial label comprises a nucleic acid sequence, and wherein the spatial label is associated with a coordinate in a sample, and wherein the molecular label comprises a nucleic acid sequence, and wherein the molecular labels of different stochastic barcodes are different from one another; generating an indexed library of the stochastically barcoded targets; estimating the number of each of the plurality of target molecules using the molecular label, wherein estimating the number of the plurality of target molecules using the molecular label comprises determining sequence information of the spatial labels and molecular labels of the plurality of the stochastic barcodes and counting the number of the molecular labels with distinct sequences; and identifying the spatial location of each of the plurality of target molecules using the spatial label, wherein the spatial locations of the plurality of targets in the sample are on a surface of the sample, inside the sample, subcellularly in the sample, or any combination thereof, wherein the sample is: (i) a tissue, a cell monolayer, fixed cells, a tissue section, or any combination thereof; and/or (ii) intact during stochastically barcoding the plurality of targets in the sample. stochastically barcoding the plurality of target molecules in the sample using a plurality of stochastic barcodes, wherein each of the plurality of stochastic barcodes comprises a spatial label and a molecular label, wherein the spatial label comprises a nucleic acid sequence, and wherein the spatial label is associated with a coordinate in a sample, and wherein the molecular label comprises a nucleic acid sequence, and wherein the molecular labels of different stochastic barcodes are different from one another; generating an indexed library of the stochastically barcoded targets; estimating the number of each of the plurality of target molecules using the molecular label, wherein estimating the number of the plurality of target molecules using the molecular label comprises determining sequence information of the spatial labels and molecular labels of the plurality of the stochastic barcodes and counting the number of the molecular labels with distinct sequences; and identifying the spatial location of each of the plurality of target molecules using the spatial label, wherein the spatial locations of the plurality of targets in the sample are on a surface of the sample, inside the sample, subcellularly in the sample, or any combination thereof, wherein the sample is: (i) a tissue, a cell monolayer, fixed cells, a tissue section, or any combination thereof; and/or (ii) intact during stochastically barcoding the plurality of targets in the sample. (i) a tissue, a cell monolayer, fixed cells, a tissue section, or any combination thereof; and/or (ii) intact during stochastically barcoding the plurality of targets in the sample.